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

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

Asked by 5 years ago

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)

0
':connect()' Is depracted, i'd prefer :Connect(), also i'm gonna help you out. Tell me what the scripts supposed to do. User#22722 20 — 5y
0
please don't name string values, or int values, or number values "Value", it gets extremely confusing theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

0
:remove() is deprecated theking48989987 2147 — 5y
0
also, the ~= nil isn't necessary unless the "HumanoidRootPart" is a Boolean theking48989987 2147 — 5y
Ad

Answer this question