On tool being equiped player should become anchored

I want to make a tool that will anchor a player upon being equipped and unanchor the player when the tool is unequipped. I have tried just doing things like Handle.anchored = true but they don’t work how I want them to.

This happens: https://gyazo.com/22ad528e6282a0f5f12d1a165c7929f7

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character
local AnchorPoint = player:FindFirstChild("Torso")

if tool.Equipped then 
	AnchorPoint.Anchored = true 
elseif tool.Unequipped then
	AnchorPoint.Anchored = false
else AnchorPoint.Anchored = false
end

You could try doing something like this instead, connecting the tool.Equipped and tool.Unequipped events to a function:

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character
local AnchorPoint = player:FindFirstChild("Torso")

tool.Equipped:Connect(function()
     AnchorPoint.Anchored = true
end)

tool.Unequipped:Connect(function()
     AnchorPoint.Anchored = false
end)

Let me know if this doesn’t work, I’m away from my computer and I couldn’t test the code.

It didn’t work, this error came up:
tool.Unequipped:Connect(function(:1: attempt to index nil with ‘Parent’

Could I see a screenshot of the explorer? Is the script a child of the tool object?

The script is called Anchor: https://gyazo.com/3ceb2927713b28e0080d85820f6de021

Try using the humanoidrootpart instead of the torso

this should also be a server script.

I see the issue, LocalPlayer only works in local scripts.

Edit: Use @Afraid4Life’s solution, that should work.

1 Like
local tool = script.Parent
local character
local AnchorPoint 

tool.Equipped:Connect(function()
    character = tool.Parent
    AnchorPoint = character.HumanoidRootPart
    AnchorPoint.Anchored = true
end)

tool.Unequipped:Connect(function()
    AnchorPoint.Anchored = false
end)

put this in a server script

2 Likes

local AnchorPoint = character:FindFirstChild("Torso")


I don’t know if thats the problem, but you can’t find any Torso in the player, only in character

It worked! Thanks, will give you some credit, the others will also get some credit for the help.

1 Like