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

Why does my script to increase a leaderstat not work?

Asked by 6 years ago

So in a game I am making I have a lederstat named "Toads" that is suposed to increase everytime you click with a custom made tool named "Mushroom" but for somereason it does not work.

Here are my scripts related to my leaderstats:


function playerAdded(plr)

local stats = Instance.new("IntValue", plr) stats.Name = "leaderstats"

local money = Instance.new("IntValue", stats) money.Name = "Toads" money.Value = 0

end

game.Players.PlayerAdded:connect(playerAdded)


tool.Activated:Connect(function() game.Players.Player1.leaderstats.Toads.Value = game.Players.Player1.leaderstats.Toads.Value + 1 end)

2 answers

Log in to vote
0
Answered by
Jacksez 15
6 years ago

Hello, this script is for a surface gui.

plr = game:GetService("Players").LocalPlayer

local leaderstats = Instance.new("IntValue", plr)
leaderstats.Name = "leaderstats"

local money = Instance.new("IntValue", stats)
money.Name = "Money"
money.Value = 0

gui = Put your designated path to the GUI
button = GUI.Put your button path

button.MouseButton1Down:connect(function()
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value +1

This works for a normal script and local script

Ad
Log in to vote
0
Answered by
caipira 29
6 years ago

Hey put this script i made in a LocalScript inside of StarterPlayerScripts:

plr = game.Players.LocalPlayer -- get the player (only works at a LocalScript)

local stats = Instance.new("IntValue", plr)
stats.Name = "leaderstats"

local money = Instance.new("IntValue", stats)
money.Name = "Toads" 
money.Value = 0




backpack = plr:WaitForChild("Backpack") -- will wait for the backpack loads
tool = backpack.Tool -- get the tool inside the backpack


tool.Activated:Connect(function()
plr.leaderstats.Toads.Value = plr.leaderstats.Toads.Value + 1

end)

please study my script and see what is wrong with your

0
i'm sorry if i can't teach you, but i haven't mastered the english yet, so for now i can only fix your script. caipira 29 — 6y

Answer this question