Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I need some help with my Gold leaderstat for my mining game. Can someone help?

Alright to my issue is. When I add the give leaderstat variables it breaks the mining script. I need it once you Destroy the block by mining it it adds to the "Gold" Leaderstat. Heres the code. So when the block gets removed with d:remove I need it to also add to the Gold Leaderstat. So can someone help me?

function onTouched(part)

local shovel = part.Parent
local d = script.Parent
if (shovel.Name == "Swuvle") then
if (part.Name == "Handle") then
local v = script.Parent.Value

if (v.Value ~= 0) then
v.Value = v.Value - 1
d.Transparency = d.Transparency + 0.5

else
d:remove()

end
end
end
end
script.Parent.Touched:connect(onTouched)

2 comments

0

':connect()' Is depracted, i'd prefer :Connect(), also i'm gonna help you out. Tell me what the scripts supposed to do.

0

please don't name string values, or int values, or number values "Value", it gets extremely confusing

1 answer

You will need to establish a "Gold" leaderstat if you haven't already. You can do this by putting this script into ServerScriptStorage:

game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Model", plr)
stats.Name = "leaderstats"
local gold = Instance.new("IntValue",plr)
gold.Name = "Gold"
end)

Once you have that script written, you will want to change your mining code to look like this:

function onTouched(part)

local shovel = part.Parent
local d = script.Parent
if (shovel.Name == "Swuvle") then
if (part.Name == "Handle") then
local v = script.Parent.Value

if (v.Value > 0) then
v.Value = v.Value - 1
d.Transparency = d.Transparency + 0.5

else
d:remove()

local character = shovel.Parent
if character:FindFirstChild("HumanoidRootPart") ~= nil then
local plr = game.Players:FindFirstChild(character.Name)
plr.leaderstats.Gold.Value = plr.leaderstats.Gold.Value + 1
end

end
end
end
end
script.Parent.Touched:Connect(onTouched)

Let me know if you have any other questions.

2 comments

0

:remove() is deprecated

0

also, the ~= nil isn't necessary unless the "HumanoidRootPart" is a Boolean

This discussion is preserved as it was. New answers, comments, and votes are closed.