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)
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.
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)
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.
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
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.