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

How to make player get currency when he/she has mined a block?

Asked by 4 years ago
Edited 4 years ago

I have gotten a shovel script, but I don't know how to make it so that the player gets awarded currency every time he/she mines a block.

01local Mouse = game.Players.LocalPlayer:GetMouse()
02local tool = script.Parent
03local Equipped = false
04 
05tool.Equipped:Connect(function()
06    Equipped = true
07end)
08 
09tool.Unequipped:connect(function()
10    Equipped = false
11end)
12 
13Mouse.Button1Down:Connect(function(player)
14    if Equipped then
15        local Target = Mouse.Target
View all 21 lines...

2 answers

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Okay, you're doing good.

First, make a RemoteEvent and put it in ReplicatedStorage.

After that, name it whatever you like.

Once you do that, paste this code into the local script: (You may need to edit it)

01local Mouse = game.Players.LocalPlayer:GetMouse()
02local tool = script.Parent
03local Equipped = false
04 
05tool.Equipped:Connect(function()
06    Equipped = true
07end)
08 
09tool.Unequipped:connect(function()
10    Equipped = false
11end)
12 
13Mouse.Button1Down:Connect(function(player)
14    if Equipped then
15        local Target = Mouse.Target
View all 24 lines...

Okay, now please paste in a server script in ServerScriptStorage

01game.Players.PlayerAdded:Connect(function(player)
02    local folder = Instance.new("Folder")
03    folder.Name = "leaderstats"
04    folder.Parent = player
05    local Currency = Instance.new("NumberValue")
06    Currency.Name = "Blocks"
07    Currency.Parent = folder
08    Currency.Value = 0
09end)
10local RE = game.ReplicatedStorage.RemoteEvent -- Change RemoteEvent to whatever it's called.
11RE.OnServerEvent:Connect(function(player)
12player.leaderstats.Blocks.Value = player.leaderstats.Blocks.Value + 1
13end)
0
I added .Value to player.leaderstats.Blocks and it worked! Thanks! DeuceyTheHonk 2 — 4y
0
oh, i forgot about that, nice job raid6n 2196 — 4y
0
oh, i forgot about that, nice job raid6n 2196 — 4y
0
oh, i forgot about that, nice job raid6n 2196 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Create two remote events in the replicated storage and on line 18, delete the "Target:Destroy()" with

1game.ReplicatedStorage.firstEvent:FireServer(game.Players.LocalPlayer)
2game.ReplicatedStorage.secondEvent:FireServer(Target)
3--// Replace firstEvent and secondEvent with the name of your remote event \\--

if you don't already have the currency, then make a script in ServerScriptStorage. This is the code for it:

1game.Players.PlayerAdded:Connect(function(p)
2    local folder = Instance.new("Folder")
3    folder.Name = "leaderstats" --// If you don't want the currency to appear on the leaderboard, change leaderstats to something else \\--
4    folder.Parent = p
5    local Currency = Instance.new("NumberValue")
6    Currency.Name = "put whatever you want in here"
7    Currency.Parent = folder
8    Currency.Value = 0 --//If you want the player to start wiith a certain curency when they join,  change it to that \\--
9end)

Now that you done that, make another script in ServerScriptService and the code is this:

1local rStore = game.ReplicatedStorage
2rStore.firstEvent.OnServerEvent:Connect(function(p)
3    p.leaderstats.currency.Value = p.leaderstats.currency.Value + 1 //--Change leaderstats to name of ur folder, currency to ur currency name, and 1 to how much you want to give your player \\--
4end)
5rStore.secondEvent.OnServerEvent:Connect(function(t)
6    t:Destroy()
7end)

That's it! If you have any problems reply to this and I will try my best to help.

0
I'm having a problem where i can't even mine the part. Do I need to put a script into the the RemoteEvent? I don't know a lot of things since I am VERY new to scripting. DeuceyTheHonk 2 — 4y

Answer this question