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

How Do I make it so if i chop down a tree it gives me a leaderstat currency ie: "Lumber"? (Answered)

i need to make it so when i chop a tree its adds 15 "Lumber" to the leaderboard? Thanks, TSSRafa.

2 comments

0

if  my answer answered your question, mark it as an answer pls.

0

You can go to my answer there should be a button that allows you to do it, but nvm, the post has been marked as "answered" for some reason

2 answers

All you have to do is add a line of code that increase the value of "Lumber" to your tree chopper script when it chopped a tree

example line of code

player.leaderstats.Lumber.Value = player.leaderstats.Lumber.Value  + 15

4 comments

0

Ahh ok Ty

0

now it says player underlined with blue

0

well you gotta change the "player" to the player that is using the script, if u want help make another post and post the script there, click the "lua" button when making a post and paste the script between the "~" symbols

0

Wooo boy downvoted, ok then.

Hello! You will need a RemoteEvent in Replicated Storage called "GiveLumber" (name it whatever). Inside the local script for the axe, you will first need to define the remote.

local lumber_remote = game:GetService("ReplicatedStorage").GiveLumber

Next, "tell" the remote to activate by doing the following (this goes inside your Axe local script):

local lumber_amount = 15
lumber_remote:FireServer(lumber_amount)

Then, you need to make a normal Script and place it in ServerScriptService. (you can name it to your liking)

Inside that script, you will need to define the remote again and add the leaderstat value, here's how! (This goes inside your new Script placed in ServerScriptService)

local lumber_remote = game:GetService("ReplicatedStorage").GiveLumber

lumber_remote.OnServerEvent:Connect(function(player, amount)
	player.leaderstats.Lumber.Value = player.leaderstats.Lumber.Value + amount
end)

To explain what happens inside the Server Script, when you activate a remote through a local script, the Player parameter is already defined for you, therefore you don't have to send it through the local script, all you have to do is define it within the "function([plr])" part. Since we sent the "lumber_amount" through the ":FireServer" part, that will be an item that you can "grab" from the local script and be able to read.

There you have it! For future reference, you need to use Remotes to send local data to the server since local scripts are only client-based. Hope this helps!

If you need help with Remotes, here is the Developer Wiki link: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

1 comment

0

-1 as this code is not secure at all, they can just pass like 1000000 lumbers for free. The #1 rule of filtering enabled is quite literally, never trust the client

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