Local Pick Up Tool Roblox

Is there anyone who can help me with an issue i am having where when a player clicks on a tool they get it but then the tool destroys and another player cant get it? this is my current script
– Script in the tool –

local Storage = game:GetService("ServerStorage")


local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")

ClickDetector.MouseClick:connect(function(Player)
	if Player and Player.Character then
		local Backpack = Player:WaitForChild("Backpack")
		for i = 1, #ToolNames do
			local Tool = Storage:FindFirstChild(ToolNames[i])
			if Tool then
				Tool:clone().Parent = Backpack
				wait(0.1)
				script.Parent:Destroy()
			end
		end
	end
end)
4 Likes

Probably the script.Parent:Destroy() part, if you dont want the same player to be able to pick it up twice you could add an extra check to see if they already have it.

2 Likes

yeah but i need everyone in the server to get it, so if it gets destroyed then no one else can grab it.

2 Likes

Hey, if you just want the player to be able to pick up the tool you can simply place it into their backpack instead of destroying it. Additionally, like Sofia said, you should probably check if the player already has the tool. Check out my code below and see if it works for you.

Hope this helps!

local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
local toolName = script.Parent.Name

ClickDetector.MouseClick:connect(function(Player)
	if Player and Player.Character then
		local Backpack = Player:WaitForChild("Backpack")
		if not Backpack:FindFirstChild(toolName) then
			Part.Parent = Backpack
			script.Enabled = false
		end
	end
end)
2 Likes

is this gonna be a local script or a normal one?

1 Like

This would be a regular script.

I don’t really understand what disabling the script does though?

1 Like

Screen Shot 2023-07-05 at 12.02.54 PM
this is that is happening when i equip now.

1 Like

Check if the tool (any of its parts) are anchored, and if they are, unanchor them

i dont think its the part, the script its self is off somehow, im trying to get a local script and make the selection box and tool transparent for the player who already gets the tool.

1 Like

oh if that’s what you were talking about then you’d have to use a remote event in which you set the transparency of both items (although destroying them seems more efficient) in a local script

2 Likes

do u think firing remote events is necessary for this?

if you’re trying to disable it specifically for the player that gets the tool, yes, you need a remote event

alright let me try and fix the script.

So guys what you need to do is you have to make a local script in starter character scripts and put code in there and make a server script and put it in the part.

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