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

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

Asked by 4 years ago
Edited 4 years ago

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

0
if  my answer answered your question, mark it as an answer pls. Azure_Kite 885 — 4y
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 Azure_Kite 885 — 4y

2 answers

Log in to vote
-1
Answered by 4 years ago

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
0
Ahh ok Ty User#31501 0 — 4y
0
now it says player underlined with blue User#31501 0 — 4y
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 Azure_Kite 885 — 4y
0
Wooo boy downvoted, ok then. Azure_Kite 885 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

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

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* programmerHere 371 — 4y

Answer this question