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

How to make a currency giver that only gives to the player one time?

Asked by 2 years ago

Hello

I am trying to make a coin system where players can collect a coin that that then disappears. I want everyone to be able to collect the coin though and i don't know how to make it disappear or deactivate for only one player once they've collected it and still work for those who haven't collected it yet. Here is the code i am using

local ting = 0

function onTouched(hit)

    if ting == 0 then 
    ting = 1
    local check = hit.Parent:FindFirstChild("Humanoid")

    if check ~= nil then 

        local user = game.Players:GetPlayerFromCharacter(hit.Parent)
        local stats = user:findFirstChild("leaderstats")

        if stats ~= nil then 
            local wins = stats:findFirstChild("Wins")
            wins.Value  = wins.Value  +1 
        wait(120) 
        end 

    end 

    ting = 0
    end 

end 

script.Parent.Touched:connect(onTouched)

There is a wait function after the currency is added but this seems to disactivate the coin for all players. I want it to still work for the ones who haven't touched it yet.

Thanks!

1 answer

Log in to vote
0
Answered by 2 years ago

Make sure to learn how filtering enabled works, because it is one of most important things in roblox scripting. Make localscript to delete token, so it will be client-sided.

Ad

Answer this question