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.


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)

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)

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)
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

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.

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