How to unanchor tool after player picks it up

I have a grenade on the map that’s anchored. But I can get it to unanchor after the player picks it up.

local tool = script.Parent
local plr = game:GetService("Players").LocalPlayer
local anim = Instance.new("Animation")
local sound1 = tool:WaitForChild("PinPull2")
local sound2 = tool:WaitForChild("PinPull4")
local sound = {sound1, sound2}
anim.AnimationId = 'https://www.roblox.com/Assest?ID=13771756559'
local track
local db = false


tool.Activated:Connect(function()
	
	tool.Handle.Anchored = false
	if db == false then
		db = true
		game.ReplicatedStorage.activate:FireServer(plr:GetMouse().Hit,tool)
		task.wait(10)
		db = false
	end
end)

tool.Equipped:Connect(function()

	sound[math.random(1, #sound)]:Play()
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim) 
	track.Priority = Enum.AnimationPriority.Action
	track:Play()

end)

tool.Unequipped:Connect(function()
	if track then
		track:Stop()
		sound[math.random(1, #sound)]:Stop()
	end
end)

Try this:

local tool = script.Parent
local plr = game:GetService("Players").LocalPlayer
local anim = Instance.new("Animation")
local sound1 = tool:WaitForChild("PinPull2")
local sound2 = tool:WaitForChild("PinPull4")
local sound = {sound1, sound2}
anim.AnimationId = 'https://www.roblox.com/Assest?ID=13771756559'
local track
local db = false


local originParent=tool.Parent
repeat
	wait()
until tool.Parent~=originParent
tool.Handle.Anchored=false


tool.Activated:Connect(function()
	
	if db == false then
		db = true
		game.ReplicatedStorage.activate:FireServer(plr:GetMouse().Hit,tool)
		task.wait(10)
		db = false
	end
end)

tool.Equipped:Connect(function()

	sound[math.random(1, #sound)]:Play()
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim) 
	track.Priority = Enum.AnimationPriority.Action
	track:Play()

end)

tool.Unequipped:Connect(function()
	if track then
		track:Stop()
		sound[math.random(1, #sound)]:Stop()
	end
end)

The player gets stuck on the grenade but works when I unequip and equip.

But when thrown the grenade goes back to its original anchor position.

Is it just the handle in the tool or is there more parts? If there are multiple please post a screenshot showing the descendants of the tool.

Just relized you are doing it in a local script make a new script in the tool (regular script) and paste this:

local originParent=tool.Parent
repeat
	wait()
until tool.Parent~=originParent
tool.Handle.Anchored=false
script:Destroy()

quick tip:
If you unanchor something on a client it wont do it for the rest of the server

I’m an getting error. What should the parent be?

The parent shall be the tool and i forgot to tell you to set the tool variable to script.parent
so just add this at the top

local tool = script.Parent

the red line under the tool indicates that its an error

1 more tip:
Anything done on the client wont be visible on the server
I looked at youre code agian and it seems that you play audio in the client script that means only the player who uses it will hear the “PinPull2” or “PinPull4” sound effects

I think you should look into the diffrance between client and server scripting.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.