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