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