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?
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.
A Remote Event isn’t needed here. You can directly do everything in a server script.
I edited and fixed the code above, please try again.
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)
Are you sure the “requireshandle” in the tool is turned off?
It was turned on, I turned it off and tried again, still nothing happening, nothing in output either.
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?
I placed them the same way you told me, it still doesn’t seem to work for some strange reason though
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.
It’s supposed to be a LocalScript
, which you made a regular script I assume
It’s a localscript inside the tool I just renamed it to script, not sure why I did that
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
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)
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)