I want to make it so whenever a player uses a soda tool they get +1 point, which is a leaderstat currency. This is for a game im currently making so any help will be very appreciated.
✓ ANSWER ACCEPTED
How do I make so whenever a player uses a tool they get a +1 leaderstats currency?
1 answer
✓ Accepted answer
What I would use is GetPlayerFromCharacter(), since you're using a tool I see no reason why you shouldn't you use.
Like so:
Tool = script.Parent -- Define your tool
Players = game:GetService('Players') -- For defining the player
Tool.Activated:Connect(function() -- In this case, when you click down (activating the tool).
local Player = Players:GetPlayerFromCharacter(Tool.Parent) -- Find the player's Character through the tool parent, henceforth defining the player.
if Player then -- Just a safe check to make sure it's found the player
if Player:FindFirstChild('leaderstats') and Player.leaderstats:FindFirstChild('Points') then -- We make to make sure the player both has the leaderstats folder and the points value.
Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 1 -- Now add the points
end
end
end)
5 comments
0
Sorry, it is a bit messy due to how the website code block system works, but I hope you get the jist of it.
0
ummm, is this meant to be in a localscript?
0
in a LocalScript you can just do game.Players.LocalPlayer
0
Do not put it in a localscript. You will not be able to replicate the new value to the server if it's not on a server script.
0
Server script.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Hello x300z, this is not a request site, please give us an example with one of your scripts.
Wait nvm one of your posts has answered it...