Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect if a player is already "Frozen"?

Asked by 5 years ago

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:

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        script.Disabled = true
        local torso = hit.Parent:FindFirstChild("HumanoidRootPart")
        local frozen = Instance.new("Part")
        frozen.Name = "IceCube"
        frozen.Size = Vector3.new(6,8,6)
        frozen.Material = "Ice"
        frozen.BrickColor = BrickColor.new("Pastel Blue")
        frozen.Transparency = "0.3"
        frozen.Anchored = false
        frozen.Parent = torso
        local weld = Instance.new("Weld")
        weld.Parent = frozen
        weld.Part0 = frozen
        weld.Part1 = torso
        hit.Parent.HumanoidRootPart.Anchored = true
        for i = 1, 10 do
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -3
            wait(0.2)
        end
        hit.Parent.HumanoidRootPart.Anchored = false
        frozen:Remove()
        script:Remove()
    end
    wait(0.025)
end)

2 answers

Log in to vote
1
Answered by
Syclya 224 Moderation Voter
5 years ago
Edited 5 years ago

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

0
Thanks for the help! ScriptedSouls 5 — 5y
0
you're welcome, and sorry for the late reply! Syclya 224 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

This one sounds easy enough, you add a part named "IceCube" to them once you freeze them, so check if they have it already!

--NOTE: Pseudocode, homework for OP!
--...
local Connection
Connection=Part.Touched:connect(function(Part)
    if hit.Parent:FindFirstChild("Humanoid") then
        if hit.Parent:FindFirstChild("IceCube",true) then --Already frozen! (Search recursively)
            -...
        else --Not yet!
            -...
        end
    end
    Connection:Disconnect() --Make sure this one projectile doesn't hit them *twice*!
end)
0
This is a pretty computationally expensive way of doing things - instantiating and rendering a part just for a simple boolean check seems excessive. plasmascreen 143 — 5y
1
I'll be practicing pseudocode haha, thanks for the help too. ScriptedSouls 5 — 5y
0
Not necessarily, the part is already there for I assume visual purposes, so might as well use it. Jahaziel_VanDerHas 238 — 5y

Answer this question