Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't this working correctly?

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.

5 comments

0

WAIT! FORGOT THE VALUE AFTER TAGGER! DANGIT!

0

Ugh still isnt working

0

What value? Edit your question and add it in so I know what to fix...

0

Oh, nvm.

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.

2 answers

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.