Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Add leaderstats point giver to tool equipped when clicking a part?

Right, I have created a script that made a block turn transparent when clicked with a tool but I would like it to add a point to the leaderstats too. Here is the code, it's only a simple one :)

:

Tool = script.Parent

Tool.Activated:Connect(function(sword) local Block = game.Workspace.Block Block.CanCollide = true Block.Transparency = 1 wait (5) Block.CanCollide = false Block.Transparency = 0 end)

1 answer

✓ Accepted answer

You need to learn how to do this first instead of going straight to scriptinghelpers to ask others to make a script for you. I'll just explain how it works. I have two scripts (LocalScript and server Script), and I have a RemoteEvent in ReplicatedStorage.

Local Script

local player = game.Players.LocalPlayer -- Because this is in a LocalScript, I have to reference a player this way

local leaderstats = Instance.new("Folder",player) -- This folder will hold your values
leaderstats.Name = "Leaderstats"

local points = Instance.new("IntValue",leaderstats) -- If you want decimals in your points, you can change this to NumberValue instead.
points.Name = "Points"

tool = script.Parent

tool.Activated:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer() -- You need to use a RemoteEvent because only the server can access the leaderstats, not the client.

Server Script

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) -- You'll need the player argument to give a point to the player who activated their tool
	local newValue = player.Leaderstats.Points.Value + 1 -- This gives the player one point. Always remember to include Value and not just do player.Leaderstats.Points
	player.Leaderstats.Points.Value = newValue -- This replaces the current value with the new one.

If you'd like, you can add a debounce so players don't spam.

Hope this helps!

2 comments

0

Thank you @LoveSpeaksOutTruth, but where is the best place to learn to script more?

0

I always like to go to the Roblox Developer Hub. Tutorials are always great too if you learn better by listening and watching. There's also scriptinghelpers. I know I said that you shouldn't ask a question without showing your attempt to solve it. What I mean is you could always look up questions similar to the one you have and it may be answered by a response to someone else's question.

This discussion is preserved as it was. New answers, comments, and votes are closed.