I made this script which was used to add 1 to the player's Coin currency. I was wondering if there's a better way to do this because it's in a loop which sometimes adds too many sometimes.
Script In ClickDetector
while true do wait(4.5) local kids = game.Players:GetChildren() for i=1, #kids do if kids[i]:FindFirstChild('leaderstats')~=nil and kids[i].leaderstats:FindFirstChild('Items')~=nil then script.Parent.MouseClick:Connect(function() kids[i].leaderstats.Items.Value = kids[i].leaderstats.Items.Value + 1 script.Parent.Parent.Transparency = 0.7 script.Parent.MaxActivationDistance = 0 script.Parent.Parent.CanCollide = false wait(4.5) script.Parent.Parent.Transparency = 0 script.Parent.MaxActivationDistance = 34 script.Parent.Parent.CanCollide = true end) end end end
I figured it out!
I just have to access the players leaderstats in the function
script.Parent.MouseClick:Connect(function(player) local leads = player:FindFirstChild("leaderstats") if leads then local item = leads:FindFirstChild("Items") if item then item.Value = item.Value + 1 script.Parent.Parent.Transparency = 0.7 script.Parent.MaxActivationDistance = 0 script.Parent.Parent.CanCollide = false wait(4.5) script.Parent.Parent.Transparency = 0 script.Parent.MaxActivationDistance = 34 script.Parent.Parent.CanCollide = true end end end)