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.
local Mouse = game.Players.LocalPlayer:GetMouse() local tool = script.Parent local Equipped = false tool.Equipped:Connect(function() Equipped = true end) tool.Unequipped:connect(function() Equipped = false end) Mouse.Button1Down:Connect(function(player) if Equipped then local Target = Mouse.Target Mouse.TargetFilter = game.Players.LocalPlayer.Character if Target.Name == "Dirt" then Target:Destroy() end end end)
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)
local Mouse = game.Players.LocalPlayer:GetMouse() local tool = script.Parent local Equipped = false tool.Equipped:Connect(function() Equipped = true end) tool.Unequipped:connect(function() Equipped = false end) Mouse.Button1Down:Connect(function(player) if Equipped then local Target = Mouse.Target Mouse.TargetFilter = game.Players.LocalPlayer.Character if Target.Name == "Dirt" then Target:Destroy() wait() local RE = game.ReplicatedStorage.RemoteEvent -- Change RemoteEvent to whatever it's called. RE:FireServer(player) end end end)
Okay, now please paste in a server script in ServerScriptStorage
game.Players.PlayerAdded:Connect(function(player) local folder = Instance.new("Folder") folder.Name = "leaderstats" folder.Parent = player local Currency = Instance.new("NumberValue") Currency.Name = "Blocks" Currency.Parent = folder Currency.Value = 0 end) local RE = game.ReplicatedStorage.RemoteEvent -- Change RemoteEvent to whatever it's called. RE.OnServerEvent:Connect(function(player) player.leaderstats.Blocks.Value = player.leaderstats.Blocks.Value + 1 end)
Create two remote events in the replicated storage and on line 18, delete the "Target:Destroy()" with
game.ReplicatedStorage.firstEvent:FireServer(game.Players.LocalPlayer) game.ReplicatedStorage.secondEvent:FireServer(Target) --// 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:
game.Players.PlayerAdded:Connect(function(p) local folder = Instance.new("Folder") folder.Name = "leaderstats" --// If you don't want the currency to appear on the leaderboard, change leaderstats to something else \\-- folder.Parent = p local Currency = Instance.new("NumberValue") Currency.Name = "put whatever you want in here" Currency.Parent = folder Currency.Value = 0 --//If you want the player to start wiith a certain curency when they join, change it to that \\-- end)
Now that you done that, make another script in ServerScriptService and the code is this:
local rStore = game.ReplicatedStorage rStore.firstEvent.OnServerEvent:Connect(function(p) 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 \\-- end) rStore.secondEvent.OnServerEvent:Connect(function(t) t:Destroy() end)
That's it! If you have any problems reply to this and I will try my best to help.