Type Index Pages
No Result Found !!!
-
Instance
- GameSettings
- DebugSettings
- BodyMover
- WeldConstraint
- HttpRbxApiService
- NotificationService
- Translator
- Lighting
- Beam
- GuiService
- UserInputService
- Studio
- Plugin
- HttpService
- Mouse
- BindableEvent
- RunService
- Pages
- Humanoid
- TestService
- PathfindingService
- Chat
- NetworkPeer
- Feature
- CharacterAppearance
- Constraint
- NetworkReplicator
- JointInstance
- Light
- BasePlayerGui
- AnalyticsService
- NetworkMarker
- BinaryStringValue
- FlyweightService
- Geometry
- LoginService
- InstancePacketCache
- ThirdPartyUserService
- TouchInputService
- RuntimeScriptService
- GuidRegistryService
- PartOperationAsset
- DialogChoice
- PhysicsService
- AdService
- TextService
- MarketplaceService
- TeleportService
- Accoutrement
- GamePassService
- AssetService
- InsertService
- PointsService
- ChangeHistoryService
- ServerScriptService
- JointsService
- LogService
- InputObject
- Toolbar
- LuaSettings
- RenderSettings
- AnimationTrack
- PhysicsSettings
- NetworkSettings
- CFrameValue
- Animation
- Color3Value
- BoolValue
- BrickColorValue
- Vector3Value
- AnimationController
- BindableFunction
- Button
- Trail
- LocalizationTable
- LocalizationService
- DebuggerBreakpoint
- DebuggerWatch
- ScriptDebugger
- Animator
- Attachment
- RemoteFunction
- RemoteEvent
- PluginManager
- Camera
- Stats
- Sky
- StarterPlayer
- Dragger
- TerrainRegion
- Path
- TextFilterResult
- Dialog
- StatsItem
- GoogleAnalyticsConfiguration
- ScriptContext
- ControllerService
- CacheableContentProvider
- ReflectionMetadataClasses
- ReflectionMetadataEnums
- DebuggerManager
- GuiBase
- UIBase
- LuaSourceContainer
- GuiItem
- DataModelMesh
- ServiceProvider
- ReflectionMetadataItem
- PostEffect
- PhysicsPacketCache
- TouchTransmitter
- RobloxReplicatedStorage
- Visit
- LuaWebService
- ScriptService
- FlagStandService
- VirtualUser
- SpawnerService
- TimerService
- CookiesService
- Team
- GroupService
- StarterGear
- Message
- PlayerScripts
- Configuration
- ContentProvider
- CollectionService
- Debris
- ReplicatedFirst
- ServerStorage
- ReplicatedStorage
- Folder
- TweenService
- Players
- ContextActionService
- StarterPlayerScripts
- SoundService
- KeyframeSequenceProvider
- VRService
- PluginGuiService
- Player
- Teams
- Pose
- Keyframe
- KeyframeSequence
- IntConstrainedValue
- DoubleConstrainedValue
- ForceField
- RayValue
- Fire
- Smoke
- Sparkles
- ParticleEmitter
- IntValue
- StringValue
- NumberValue
- Explosion
- ObjectValue
- SoundGroup
- UserGameSettings
- ClickDetector
- Sound
- Selection
- BadgeService
- TaskScheduler
- GlobalDataStore
- DataStoreService
- CustomEvent
- CustomEventReceiver
- VirtualInputManager
- FunctionalTest
- TweenBase
- SoundEffect
- ReflectionMetadataEvents
- ClusterPacketCache
- PVInstance
- FaceInstance
- Controller
- ReflectionMetadataCallbacks
- ReflectionMetadataFunctions
- ReflectionMetadataYieldFunctions
- ReflectionMetadataProperties
- ReflectionMetadata
- AdvancedDragger
- HapticService
- FriendService
- GamepadService
No Result Found !!!
GetInstanceAddedSignal
GetInstanceAdded is given a tag (a string) and returns a signal which fires under two conditions:
- The tag is assigned to an object within the
DataModel
(game) usingCollectionService/AddTag
- An object with the given tag is added as a descendant of the
DataModel
, e.g. by settingInstance/Parent
or similar
Subsequent calls to this method with the same tag return the same signal object. Consider also calling CollectionService/GetTagged
to get a list of objects that already have a tag (and thus won’t fire the event if they already are in the DataModel
).
See also CollectionService/GetInstanceRemovedSignal
, which returns an event that fires under similar conditions.
Parameters
Name | Type | Default | Description |
---|---|---|---|
|
Returns
Return Type | Summary |
---|---|
Code Samples
Deadly Bricks using CollectionService
This code sample causes any BasePart
with the tag “Deadly” to kill any Humanoid
that touches it. It does this using a common pattern with CollectionService
: listen for all parts with the tag, and make a connection. When the tag is removed, disconnect. Instead of copying the same kill script into many bricks, use this pattern instead!
local CollectionService = game:GetService("CollectionService") local tag = "Deadly" local function onDeadlyPartTouched(otherPart) if not otherPart.Parent then return end local human = otherPart.Parent:FindFirstChildOfClass("Humanoid") if human then human.Health = 0 end end -- Save the connections so they can be disconnected when the tag is removed -- This table maps BaseParts with the tag to their Touched connections local connections = {} local function onInstanceAdded(object) -- Remember that any tag can be applied to any object, so there's no -- guarantee that the object with this tag is a BasePart. if object:IsA("BasePart") then connections[object] = object.Touched:Connect(onDeadlyPartTouched) end end local function onInstanceRemoved(object) -- If we made a connection on this object, disconnect it (prevent memory leaks) if connections[object] then connections[object]:disconnect() connections[object] = nil end end -- Listen for this tag being applied to objects CollectionService:GetInstanceAddedSignal(tag):Connect(onInstanceAdded) -- Also detect any objects that already have the tag for _, object in pairs(CollectionService:GetTagged(tag)) do onInstanceAdded(object) end
Try tagging a part using `CollectionService` by pasting this into the Command bar: `game:GetService("CollectionService"):AddTag(workspace.Part, "Deadly")` Then, when you press Play and touch the brick with your character they should die.
How this site use cookies
This Platform uses cookies to offer you a better experience, to personalize content, to provide social media features and to analyse the traffic on our site. For further information, including information on how to prevent or manage the use of cookies on this Platform, please refer to our Privacy and Cookie Policy.