If a player is hit by a projectile they'll become frozen, but if hit again, another block will spawn. Is there a way I can check if the player is already frozen so another block won't spawn? I've been googling for hours and I just cannot find anything. Here's the code:
01 | script.Parent.Touched:connect( function (hit) |
02 | if hit.Parent:FindFirstChild( "Humanoid" ) ~ = nil then |
03 | script.Disabled = true |
04 | local torso = hit.Parent:FindFirstChild( "HumanoidRootPart" ) |
05 | local frozen = Instance.new( "Part" ) |
06 | frozen.Name = "IceCube" |
07 | frozen.Size = Vector 3. new( 6 , 8 , 6 ) |
08 | frozen.Material = "Ice" |
09 | frozen.BrickColor = BrickColor.new( "Pastel Blue" ) |
10 | frozen.Transparency = "0.3" |
11 | frozen.Anchored = false |
12 | frozen.Parent = torso |
13 | local weld = Instance.new( "Weld" ) |
14 | weld.Parent = frozen |
15 | weld.Part 0 = frozen |
You can use CollectionService for tags and so on.
If you have to freeze someone, tag them with ex: "Frozen", the method is :AddTag(). If you want to check if they already have the tag, use the method :HasTag()
For more information about CollectionService, visit below: https://developer.roblox.com/en-us/api-reference/class/CollectionService
This one sounds easy enough, you add a part named "IceCube" to them once you freeze them, so check if they have it already!
01 | --NOTE: Pseudocode, homework for OP! |
02 | --... |
03 | local Connection |
04 | Connection = Part.Touched:connect( function (Part) |
05 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
06 | if hit.Parent:FindFirstChild( "IceCube" , true ) then --Already frozen! (Search recursively) |
07 | -... |
08 | else --Not yet! |
09 | -... |
10 | end |
11 | end |
12 | Connection:Disconnect() --Make sure this one projectile doesn't hit them *twice*! |
13 | end ) |