How to make a simple tool that freezes/unfreezes the player in-game?

The title kinda explains it, I want a tool (gear) that all players would have in their inventory, and the only thing it does is that once clicked by a specific player, then that specific player will freeze (so they won’t be able to move, and their animations would also freeze too), and then when the player clicks again, it will unfreeze that specific player. How do I make such a thing?

1 Like
local mouse = game.Players.LocalPlayer:GetMouse()
local remoteEvent = game.ReplicatedStorage.RemoteEvent

-- local script inside of the tool
script.Parent.Activated:Connect(function()
	if mouse.Target.Parent:FindFirstChild("Head") then 
		remoteEvent:FireServer(mouse.Target)
	end
end)
-- server sided script inside ServerScriptService
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,Target)
	if Target then
		if Target:IsA("BasePart") then
			Target.Anchored = true
		end
	end
end)

Make sure to put “RemoteEvent” in ReplicatedStorage as well for this code to work as is.

3 Likes

A Remote Event isn’t needed here. You can directly do everything in a server script.

1 Like

For some reason, it gives me this error:

I edited and fixed the code above, please try again.

1 Like

How would you get the player’s mouse using server-sided code only?

Nothing in output, but also nothing happens whenever I click the tool after equipping it.

What could be the issue? Do I have to insert a part inside the tool for it to work? (although I was hoping I wouldn’t have anything be hold-able to the avatar)
RobloxStudioBeta_Mfl8FUZKB2

Are you sure the “requireshandle” in the tool is turned off?
obraz

1 Like

It was turned on, I turned it off and tried again, still nothing happening, nothing in output either. :frowning_face:

Here is a revised code in the tool:

local mouse = game.Players.LocalPlayer:GetMouse()
local remoteEvent = game.ReplicatedStorage.RemoteEvent

-- local script inside of the tool
script.Parent.Activated:Connect(function()
	if mouse.Target.Parent:FindFirstChild("Head") then 
		remoteEvent:FireServer(mouse.Target.Parent.Head)
	end
end)

Here is a revised code in the SSS:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,Target)
	if Target then
		if Target:IsA("BasePart") then
			if Target.Anchored == true then
				Target.Anchored = false
			else
				Target.Anchored = true
			end
		end
	end
end)

Last but not least can you tell me exactly where did you put everything (localscript, script, remoteevent) and are you actually clicking an NPC or another player?

1 Like

I placed them the same way you told me, it still doesn’t seem to work for some strange reason though
RobloxStudioBeta_vx0HMQ3Qmd
RobloxStudioBeta_Ky2G13Bt87
RobloxStudioBeta_kWlGmG8C1b

Oh, one second, I think there has been a misunderstanding, I meant for the tool to be used by the player itself, so all players will have the tool in their inventory, let’s say for example I have the tool in my inventory, I would click it (click anywhere on the screen) and it would freeze me, and if i clicked it again it would unfreeze me, and so on. As in the tool is used by each person for their own avatar only, not to freeze others.

OOOOOOH that’s something completely different from what I’ve done then. It can all be done in a local script as the person before us said. Here’s the code:

local player = game.Players.LocalPlayer.Character
script.Parent.Activated:Connect(function()
	if player:FindFirstChild("Head") then
		if player.Head.Anchored == true then
			player.Head.Anchored = false
		else
			player.Head.Anchored = true
		end
	end
end)

All of it is inside of the tool, it’s a localscript. It doesn’t need anything else.

1 Like

It gives me this error in output when I click:

It’s supposed to be a LocalScript, which you made a regular script I assume

1 Like

It’s a localscript inside the tool I just renamed it to script, not sure why I did that :sweat_smile:

Also anchoring the head would give a weird head-lock behavior I’m pretty sure, so if that happens you can try replacing Head with HumanoidRootPart

1 Like

I can’t reproduce your issue. Try:

repeat task.wait(0.1) until game:IsLoaded()
local player = game.Players.LocalPlayer.Character
script.Parent.Activated:Connect(function()
	if player:FindFirstChild("Head") then
		if player.Head.Anchored == true then
			player.Head.Anchored = false
		else
			player.Head.Anchored = true
		end
	end
end)
1 Like

It seems to be semi-working now, but the animations are still there & the player can still move a bit:

robloxapp-20240207-2302159.wmv (2.0 MB)

repeat task.wait(0.1) until game:IsLoaded()
local player = game.Players.LocalPlayer.Character
script.Parent.Activated:Connect(function()
	for i,v in pairs(player:GetChildren()) do
		if v:IsA("BasePart") then
			if v.Anchored == true then
				v.Anchored = false
			else
				v.Anchored = true
			end
		end
	end
end)
2 Likes