Tool adding points to leaderstats

Hello!

So, I have this problem that is fairly simple.
I am trying to make a tool, where when you have it equipped and that you click (anywhere on the screen), it will give you +1 point in the leaderstats.

(I have already made the leaderstats script and designed the tool.)

1 Like

Its very simple, just put a script in a tool and detect when you click:

local tool = script.Parent
local leaderstat = *wherever*
tool.Activated:Connect(function()
leaderstat.Value +1
end)

This is really basic, you can also do like remote events, where a local script is in and you fire a event to add it.

Okay, so this is what I did.
(Script inside the tool)
local tool = script.Parent
local leaderstat = game.Workspace.Script
tool.Activated:Connect(function()
leaderstat.Value +1
end)

But it’s giving me an error at
leaderstar.Value + 1

(sorry i’m not good at scripts lol i am a beginner)

I don’t think the Tool.Activated works in a script. It only works in a local script

also if you are incrementing the leaderstats (leaderstats.Value + 1) doesn’t work you need to do leaderstats.Value = leaderstats.Value + 1

1 Like

No, this is false, Second off, leaderstats should be in the player as a folder, so this is how the script should look

local tool = script.Parent
local Player = tool.Parent.Parent
local leaderstat = Player.leaderstat. -- whatever the value in leaderstat is named
tool.Activated:Connect(function()
leaderstat.Point.Value = leaderstat.Point.Value + 1
end)

I’m using point as place holder.

6 Likes

To make it even shorter you can replace

leaderstat.Point.Value = leaderstat.Point.Value + 1

With

leaderstat.Point.Value += 1
4 Likes