Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I give a tool to a player if he/she has greater than or equal to a number?

Asked by 6 years ago

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!

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

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.

0
Thanks alot! K1ng_Phant0m 13 — 6y
Ad

Answer this question