'Tool.Parent = nil' deletes the player's character, instead of the tool

The code below is meant to set the Tool’s parent to nil, but instead it sets the player’s character’s parent to nil. Which is strange, i tried doing ‘Tool = nil’ but that appears to do nothing.

Event = script.Parent:WaitForChild("UnlockBunkerEvent")
Sound = script.Parent:WaitForChild("Sound")

Event.OnServerEvent:Connect(function(Tool)
    script.Parent.Parent.Padlock:Destroy()
    Sound:Play()
    script.Parent.Name = "UnlockPart_Unlocked"
    Tool.Parent = nil
end)

If you’re referencing the tool.Parent, you are referencing the player’s character as the tool is parented to the character. The proper method to delete the tool is by using:

Tool:Destroy();

How come you can change the objects parent, by doing ‘Part.Parent = workspace’. But doing ‘part.Parent = nil’ wont work? I’m trying to simulate the player dropping a tool. And doing :Destroy() doesn’t work, i remember doing it before.

My misunderstanding. You’d be correct on that. Try printing print(Tool:GetFullName()) and see where the tool falls under. You may be accidentally referencing the character instead of the tool.

1 Like

Oh my bad. I forgot that the first argument for a server event is the player,

image

Changing the arguments to somthing like this: Event.OnServerEvent:Connect(function(plr, Tool) appears to solve this issue!

2 Likes