Hey fellow developers, recently I was making a tool giver, and in the script I’m trying to check if the player already has this tool so that it isn’t given twice or more.
The problem is that to check it I’m using :FindFirstChild(tool.Name) to make the script re-usable, and it only works with a specific name so I can’t use a variable. (The variable works, it’s just the route to the tool and it didn’t give any errors)
Is there any way to do what I’m trying to do? If not, are there any alternatives? I know you can probably do this with tables to check the entire inventory of a player, but I’m not very experienced with tables.
I had an issue like this and managed to fix it today because for some reason checking if the player has the tool didn’t work. What I did was make a bool value set to false and use if statements to check if he pressed a button and if has is false then at the end of the if statment block thing I just set the bool value to false when I put it at the start it didn’t work
I think you mean a debounce variable, well that’s a good alternative but have in mind that multiple players have to get that tool and the giver is a server sided script
I know I can do this, but as I said I’m trying to make it as re-usable as possible to avoid forgetting to change parts of the script. For now that I don’t have an alternative, I’m using this method
Could you send the script you’re currently using so that we have something to work on? Also, how is the tool received? e.g. part touch, button click, etc
local tool = game.ReplicatedStorage.Tools.FlashLight
local price = 25
local deletesfrominv = false
script.Parent.MouseClick:Connect(function(plr)
if plr:WaitForChild("leaderstats").Deaths.Value >= price then
local hastool = plr.Backpack:FindFirstChild(tool.Name) or plr.Character:FindFirstChild(tool.Name)
if not hastool then
tool:Clone().Parent = plr.Backpack
if deletesfrominv == false then
plr.CharacterAdded:Connect(function()
tool:Clone().Parent = plr.Backpack
end)
end
end
end
end)
No, as I said in the beginning of this thread it’s not any error, I was just wondering if I could make the script more re-usable, because you can only use strings inside :FindFirstChild