Your method of getting a random tool from the ServerStorage is correct, I assume you just don't know where to put it in the first code block?
Before we start, you should look into formatting your code correctly, specifically in reference to indentation. It makes everything a lot easier to look at at make changes to.
Anyway, here is how I would insert that bit into your code:
local tools = game.ServerStorage.Folder['foldername']:GetChildren()
local debounce = true
script.Parent.ClickDetector.MouseClick:connect(function(plr)
if not debounce then return end
local treat = tools[math.random(#tools)]
if plr.Backpack:FindFirstChild(treat.Name) or plr.Character:FindFirstChild(treat.Name) then return end
debounce = false
treat:Clone().Parent = plr.Backpack
wait(1)
debounce = true
end)
This code should work, although I haven't tested it myself. However, it will occasionally not give any Tool, because the randomly chosen one was already given to the Player.
I'll leave it as an exercise to figure out how to keep track of what the Player doesn't have and select only from that list. :)
Finally, I keep having to say it but there is 100% absolutely nothing wrong with using connect over Connect. Yes, connect is deprecated, but that means jack. They are internally aliased to the exact same function, and will never break. If you prefer connect, use it. If you prefer Connect, use it instead. They are identical.
The same is true of wait and Wait. ROBLOX occasionally reevaluates its internal styling for consistency and these deprecations are the result of that. Any function call that differs from its non-deprecated counterpart by a capitalization change is not "truly" deprecated. These functions very rarely change functionality, if ever, and almost every time that they do the supposedly deprecated version gets the update as well.
Another set of these functions is children, getChildren, and GetChildren. They all work the exact same way. Their functionality has never changed since ROBLOX has existed, and I would reckon that, like connect, they are internally aliased to the same function. That being said, only the last one, GetChildren is not deprecated.
Case in point: ROBLOX will actually tell you if something you're using is no longer being maintained
4 comments
connect is deprecated, use Connect
wait() is deprecated, use Wait()
Hi, thank you!
@hiimgoodpack, Roblox Studio is telling me that Wait() is deprecated and not wait(). I corrected my Connect typo. Are my variables structured correctly? Thanks, again!