This is not making me anchored when touched
player = game.Workspace.Player1
script.Parent.Touched:connect(function()
player.Torso.Anchored = true
wait(15)
player.Torso.Anchored = false
end)
This is not making me anchored when touched
player = game.Workspace.Player1
script.Parent.Touched:connect(function()
player.Torso.Anchored = true
wait(15)
player.Torso.Anchored = false
end)
Well, if the game immediately starts and the script is not enabled, the script would run and look for something, anything, named Player1. Instead, we can make the workspace wait until Player1 exists in the Workspace.
Secondarily, there needs to be a Debounce value so that if a person keeps touching it the player isn't indefinitely frozen.
local player = game.Workspace:WaitForChild("Player1") -- Makes the Workspace wait until there is something inside it named Player1
local Debounce = false -- The debounce value, to keep a timer from resetting and continuing, repeatedly.
script.Parent.Touched:connect(function())
if Debounce == true then return end -- If the Debounce and thus the function is already activated, then stop.
Debounce = true -- If is is not already activated, turn it on.
player:WaitForChild("Torso").Anchored = true
wait(15)
player.Torso.Anchored = false
Debounce = false -- Now that the function is finished, we can reset it to let it be touched the next time.
end)
Firstly, I don't know if you want to Anchor anyone that triggers your event or you want some people to be anchored when they triggers the Event.
This script will Anchor anyone that triggers the event, the coding will be explain with green text for time sake.
Debounce = false
script.Parent.Touched:connect(function(Hit)--Using a Touched Event and Parameter that I chosen to name Hit.
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)--Checking to see if the Part that activated the script is connected to a Player.
if Player and Debounce ~= true then--If it is connected to a Player and Debounce is not true then...
Debounce = true
Player.Character.Torso.Anchored = true--Setting the Player's Character torso that activated the script to true
wait(15)
Player.Character.Torso.Anchored = false--Setting the Player's Character torso that activated the script to false
Debounce = false
end
end)
This script will Anchore certain Players that triggers the event, the coding will be explain with "Green text" again!
FreezeTag = {"Player","Bob","Builderman","YellowTide","Kenetec","People"}--This table store the Name of people that can be Anchored.
Debounce = false
script.Parent.Touched:connect(function(Hit)--Using a Touched Event and Parameter that I chosen to name Hit.
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)--Checking to see if the Part that activated the script is connected to a Player.
if Player and Debounce ~= true then--If it is connected to a Player and Debounce is not true then...
for _,v in pairs (FreezeTag) do--Loops through the "Table" called FreezeTag
if v == Player.Name then--If any name in the Table matches the Name of the Player that touch the script.
Debounce = true
Player.Character.Torso.Anchored = true--Setting the Player's Character torso that activated the script to true
wait(15)
Player.Character.Torso.Anchored = false--Setting the Player's Character torso that activated the script to false
Debounce = false
end
end
end
end)
K = false -- Debounce
script.Parent.touched:connect(function(Duded) --When it's touched it gets the toucher
if K = true then return end
wait (0.1)
K = true
Duded.Parent.Torso.Anchored = true --Get the toucher's body parts
Duded.Parent.Head.Anchored = true
Duded.Parent:FindFirstChild("Left Arm").Anchored = true
Duded.Parent:FindFirstChild("Left Leg").Anchored = true
Duded.Parent:FindFirstChild("Right Arm").Anchored = true
Duded.Parent:FindFirstChild("Right Leg").Anchored = true
wait (0.1)
K = false
end)
--Hope it helped !
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
I find it a better idea to anchor the player who touched, instead of a random player in workspace, but if this is your intention then go for it.
I honestly have no idea what the intentions are, but I am trying to keep as close as possible to the main script to make the intended goals.
@pyro89 The default Players and Player's Character name has changed to "Player" so you're script won't work unless he test the script by creating a 2 or more Player server. Also in line 1 what you wrote in green text is highly untrue since WaitForChild() yields the current thread until a child with the given name is found, then returns the child.