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

Is There Better Way To Add Value To A Currency Using A ClickDetector?

Asked by 4 years ago

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

1 answer

Log in to vote
0
Answered by 4 years ago

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

Answer this question