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

Why isn't this working correctly?

Asked by 9 years ago
local plr = script.Parent.Parent
local chr = plr.Character
local deb = false

--ChecksForTaggerBoolIsTrue
while true do wait()
    if plr.Tagger == true then
        chr.Torso.Touched:connect(function(hit)
            if deb == false then deb = true
                if hit:FindFirstChild("Humanoid") then
                    hit.Parent.Torso.Anchored = true
                end
            wait(2)
                deb = false
            end
        end)
        break
    end
end

The Local Script is placed in the starterGUI so every player can obtain it when the join, but for some reason its not working. The Bools are working but this isnt and there isnt an error.

0
WAIT! FORGOT THE VALUE AFTER TAGGER! DANGIT! AllianceScripter 30 — 9y
0
Ugh still isnt working AllianceScripter 30 — 9y
0
What value? Edit your question and add it in so I know what to fix... dyler3 1510 — 9y
0
Oh, nvm. dyler3 1510 — 9y
0
Basically all i want is a script where it checks if the player's tagger value is true then when other players touch their torso they freeze. AllianceScripter 30 — 9y

2 answers

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

Ok, well there's one thing that you can try. Instead of finding the player by going through the parents, try doing this:

Player=game.Players.LocalPlayer --(LocalPlayer can only be used with LocalScripts)

This ensures that the script will not lose the player it's tracking if it's moved around.

Now, for the rest of it:

local plr = game.Players.LocalPlayer --:D
local chr = plr.Character
local deb = false

while true do wait()
    if plr.Tagger.Value == true then
        chr.Torso.Touched:connect(function(hit)
            if deb == false then deb = true
                if hit.Parent:FindFirstChild("Humanoid") then --Added .Parent after hit
                    hit.Parent.Torso.Anchored = true
                end
                wait(2)
                deb = false
            end
        end)
    end
end

Try this. It should work now. I only changed a few things that you forgot to add in. Hope I helped :P

Ad
Log in to vote
0
Answered by 9 years ago

You referenced "hit" when you should've referenced "hit.Parent" to find the Humanoid on line 10, and the script can be done more efficiently. I also disconnected the touched event in the torso once tag becomes false. You can learn more about disconnecting events here.

Finished Script:

local player = game.Players.LocalPlayer
local character = player.Character
local debounce = false

player.Tagger.Changed:connect(function(value)
if value == true then
tag = character.Torso.Touched:connect(function(hit)
if not debounce and hit.Parent:FindFirstChild("Humanoid") then
debounce = true
hit.parent.Torso.Anchored = true
wait(2)
debounce = false
end
end)
else
tag:disconnect()
end
end)

Answer this question