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.
01 | local Mouse = game.Players.LocalPlayer:GetMouse() |
02 | local tool = script.Parent |
03 | local Equipped = false |
04 |
05 | tool.Equipped:Connect( function () |
06 | Equipped = true |
07 | end ) |
08 |
09 | tool.Unequipped:connect( function () |
10 | Equipped = false |
11 | end ) |
12 |
13 | Mouse.Button 1 Down:Connect( function (player) |
14 | if Equipped then |
15 | local Target = Mouse.Target |
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)
01 | local Mouse = game.Players.LocalPlayer:GetMouse() |
02 | local tool = script.Parent |
03 | local Equipped = false |
04 |
05 | tool.Equipped:Connect( function () |
06 | Equipped = true |
07 | end ) |
08 |
09 | tool.Unequipped:connect( function () |
10 | Equipped = false |
11 | end ) |
12 |
13 | Mouse.Button 1 Down:Connect( function (player) |
14 | if Equipped then |
15 | local Target = Mouse.Target |
Okay, now please paste in a server script in ServerScriptStorage
01 | game.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 |
09 | end ) |
10 | local RE = game.ReplicatedStorage.RemoteEvent -- Change RemoteEvent to whatever it's called. |
11 | RE.OnServerEvent:Connect( function (player) |
12 | player.leaderstats.Blocks.Value = player.leaderstats.Blocks.Value + 1 |
13 | end ) |
Create two remote events in the replicated storage and on line 18, delete the "Target:Destroy()" with
1 | game.ReplicatedStorage.firstEvent:FireServer(game.Players.LocalPlayer) |
2 | game.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:
1 | game.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 \\-- |
9 | end ) |
Now that you done that, make another script in ServerScriptService and the code is this:
1 | local rStore = game.ReplicatedStorage |
2 | rStore.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 \\-- |
4 | end ) |
5 | rStore.secondEvent.OnServerEvent:Connect( function (t) |
6 | t:Destroy() |
7 | end ) |
That's it! If you have any problems reply to this and I will try my best to help.