Hello, I've been trying to make a script which freezes any player near the localplayer. I've tried but it does not freeze anyone and they can still walk. I used DistanceFromCharacter to determine the distance between the localplayer and another player. I've placed the code in a localscript in the starterpack Here is my code:
local uis = game:GetService("UserInputService")
local debounce = false
local plr = game.Players.LocalPlayer
function freeze()
for i,v in pairs(game.Players:GetPlayers()) do
if v and v.Character and not plr then
local distance = v:DistanceFromCharacter(game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
if distance <= 10 then
script.Parent.Visible = true
v.Character:WaitForChild("Humanoid").WalkSpeed = 0
end
end
end
end
uis.InputBegan:connect(function(input, gp)
if input.KeyCode == Enum.KeyCode.E and not gp then
if not debounce then
debounce = true
freeze()
wait(5)
debounce = false
end
end
end)
sorry for my messy code Thank you, onepunchactivated

1 comment
Hi, thank you for your response. I've done some experimenting and found out that it worked when I used a remoteEvent, but you solved one of my problems which was to freeze a player completly. Thank you