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

How to freeze Local player instead of freezing all Players?

I'm trying to freeze a single player that steps on a platform but it freezes all players, I can't seem to get it working.

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
--testing
workspace.TestPad.Touched:Connect(function(hit)
	 LocalPlayer.HumanoidRootPart.Anchored = true
end)

5 comments

0

you cant use localplayer in a script, u can only use it in localscripts, this is how u would fix ur script: game.Workspace.TestPad.Touched:Connect(function(Hit) if Hit.Parent:FindFirstChild('Humanoid') then Hit.Parent.HumanoidRootPart.Anchored = true end end) 

0

it is a localscript

0

it is supposed to be a script, i sent u a friend request if u need more assistance, the name is StudioLegacy, and by the way the script should be in serverscriptservice or workspace

0

you cant use localplayer in a script, u can only use it in localscripts, this is how u would fix ur script

0

Server scripts are unable to access LocalPlayer since they are ServerSided. This means they don't know who the LocalPlayer is.

1 answer

✓ Accepted answer

Server scripts can't use LocalPlayer since they are server sided and not client sided. Instead of using LocalPlayer.

We can find the player by using what put in the parentheses after the .Touched function.

Make sure this is in a server script in either the Workspace or ServerScriptService.

workspace.TestPad.Touched:Connect(function(hit) --Begin the function when the pad was touched
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then --If the part that touched the pad's parent (the player) has a humanoid then
		hit.Parent.HumanoidRootPart.Anchored = true --If it does then anchor the player	
	end
end)

If this helped then please accept the answer.

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