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

how would i make a tool add leaderstats?

Asked by 4 years ago

Hey There, i've spent hours researching the web and trying things but still cant learn about functions i need my tool to add a point to my stats when it is used any help is appreciated thanks

2 answers

Log in to vote
0
Answered by
ryan32t 306 Moderation Voter
4 years ago
Edited 4 years ago

Well, You at least took the effort to do some research.. You're going to have to make use of Variables, Math, Events, Functions, and Connections.

Usually people use local scripts for tools but if we want to make an actual change to a value in leaderstats then I recommend the use of a server script.

We're going to make a tool that add 1 to a leaderstats value then the tool disappears.

-- Server Script --

-- Variables

local tool = script.Parent -- defining tool

-- Events/Connections

tool.Activated:Connect(function() -- tool "Activated" Event

    local character = tool.Parent -- defining character
    local players = game:GetService("Players") -- defining players
    local player = players:GetPlayerFromCharacter(character) -- defining player
    local leaderstats = player.leaderstats -- defining leaderstats
    local currency = leaderstats.Money -- defining currency
    local addition = 1 -- defining addition

    currency.Value = currency.Value + addition -- Adding 1 to Currency

end)

Of course.. This script may error in certain circumstances.. But that's for the better. So you can observe, problem-solve, and understand the errors.

0
Good stuff but couldn’t exploiters can edit the script and change the currency increment way higher? 123nabilben123 499 — 4y
0
No. It's a Server Script. Exploiters can't read/edit Server Script. And Exploiter's can't read/edit scripts anymore(at least for now). ryan32t 306 — 4y
0
Does it have to delete the tool after? THELFCMAN 9 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Thanks, but did you say it deletes the tool after? Cuz like I need it to stay and then we use the points to buy other tools that give points, Thanks

0
yeah i did say that.. but i guess i forgot to add that part to my script lol ryan32t 306 — 4y

Answer this question