So I made this thing where if you click the part you get a tool. I made it debounce so you can only get it once. The problem is that only one player can obtain the tool, not others. What do I do to fix this?
Script:
local ToolNames = {"Sleeping Set"}
local Storage = game:GetService("ServerStorage")
local debounce = false
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
ClickDetector.MouseClick:connect(function(Player)
if Player and Player.Character and debounce == false then
debounce = true
local Backpack = Player:WaitForChild("Backpack")
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
Tool:clone().Parent = Backpack
end
end
end
end)
local ToolNames = {"Sleeping Set"}
local Storage = game:GetService("ServerStorage")
local debounce = false
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
ClickDetector.MouseClick:connect(function(Player)
if Player and Player.Character and debounce == false then
debounce = true
local Backpack = Player:WaitForChild("Backpack")
for i,v in pairs(ToolNames) do
local Tool = Storage:FindFirstChild(v)
if Tool then
Tool:clone().Parent = Backpack
else
warn(Tool.Name..' NOT IN STORAGE')
end
end
end
end)
You don’t need a debounce, you can just check if the player has the tool already. If he does not have it, give it to him. Is that what you are trying to achieve?
local ToolNames = {"Sleeping Set"}
local Storage = game:GetService("ServerStorage")
local debounce = false
local Part = script.Parent
local ClickDetector = Instance.new('ClickDetector',Part)
ClickDetector.MouseClick:connect(function(Player)
if Player and Player.Character and debounce == false then
debounce = true
local Backpack = Player:WaitForChild("Backpack")
for i,v in pairs(ToolNames) do
local Tool = Storage:FindFirstChild(v)
if Tool then
Tool:clone().Parent = Backpack
else
warn(Tool.Name..' NOT IN STORAGE')
end
end
end
end)
local ToolNames = {"Sleeping Set"}
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
if(not Player.Character:FindFirstChild(ToolNames[i]) and not Backpack:FindFirstChild(ToolNames[i])) then
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
Tool:clone().Parent = Backpack
end
end
end
end
end)
Try this. It will give the player the tool only if he does not have it.
I just checked if his character and backpack do not contain it already, instead of the debounce, so other players can use it too.
local ToolNames = {"Sleeping Set"}
local Storage = game:GetService("ServerStorage")
local debounce = false
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
ClickDetector.MouseClick:connect(function(Player)
if Player and Player.Character and debounce == false then
debounce = true
local Backpack = Player:WaitForChild("Backpack")
for i,v in pairs(ToolNames) do
local Tool = Storage:FindFirstChild(v)
if Tool and Player.Backpack:FindFirstChild(v) == nil and Player.Character:FindFirstChild(v) == nil then
Tool:clone().Parent = Backpack
else
warn(Tool.Name..' NOT IN STORAGE')
end
end
end
end)
No, he wants the player to get it once, I removed the debounce, he want the player to get the tool only when he doesn’t have it.
If you set the debounce to false, the player will be able to get it again. But right now, when you set the debounce to only false, no other players can get the tool.
He said his script worked for him only for one player.
But why do you need a debounce? He wants the player to get the tool only once, if he clicks it again (with setting back debounce), he will get the tool again. And if he won’t change debounce back. No other players can get the tool.
He should just check if the player doesn’t have the tool. Like I did:
And also, if he didn’t want it to repeat, he could have just disconnected the function. So it will just never run again.
Actually, the script cannot check if there is a tool in the backpack, I think you’ll need to use a remote event so when you click the part then it fires the client and checks whether the player have the following tool.
Yeah and the script cannot clone a tool from the Serverscript to the player’s backpack, you’ll need to use a local script to handle this too.