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 someone within a certain radius?

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 answer

✓ Accepted answer
game Players PlayerAdded:Connect(function(localplayer)
if localplayer:DistanceFromCharacter(localplayer.Position) then
localplayer.Character.Humanoid.PlatformStand = true
end
end)

This is messy code but the parameter is player2 and everything within if then block is your code.

1 comment

0

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

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