I need to give a tool to a player when he/she has greater than or equal to a certain number of a leaderstat. How would I do that? Also, I need this tool to save after death and when he/she leaves, if possible. Thanks!
✓ ANSWER ACCEPTED
How would I give a tool to a player if he/she has greater than or equal to a number?
1 answer
✓ Accepted answer
First, you would detect when the leaderstat changes. Then, every time it changes, you would check if its new value is greater than or equal to the number. If it is, you would clone a tool from ServerStorage and put it inside the player’s backpack. You would then detect whenever their character was respawned from then on, and give them the tool every time it happened.
local valueRequired = 100
game.Players.PlayerAdded:Comnect(function(plr)
local stat = plr:WaitForChild("leaderstats"):WaitForChild("StatNameHere")
stat.Changed:Connect(function(val)
if val >= 100 then
local tool = game.ServerStorage["ToolNameHere"]:Clone()
tool.Parent = plr.Backpack
plr.CharacterAdded:Connect(function()
local tool = game.ServerStorage["ToolNameHere"]:Clone()
tool.Parent = plr:WaitForChild("Backpack")
end)
end
end)
end)
To then save this information, you would use DataStores. You would check if they had the tool when they leave, and record it in a data store. Then, when they join the game, you would load this information from the data store and give them the tool if they had it.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thanks alot!