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

Script giving points when player joins?

Asked by 6 years ago

local coinable = false

script.Parent.Touched:connect(function() if not coinable then coinable = true

    for _,Player in pairs(game.Players:GetPlayers()) do
    Player:FindFirstChild("leaderstats") 
    Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value+25
    wait(20)
    coinable = false
    end
end

end)

This is a script intended to give a player 25 points whenever they touch a brick, with a debounce/cooldown time of 20 seconds. In actuality, it gives the player 25 points when joining, and then allows them to touch the brick for points once every 20 seconds.


While your'e at it, if you don't mind explaining "for _,Player in pairs", I'm not familiar with these words and symbols

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Here you are.

local coinable = false

script.Parent.Touched:connect(function(hit) --// When touched
    local h = hit.Parent:FindFirstChild("Humanoid") --// If touched by a human
    if h then --// If it is a human
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) --// Gets the player
        if coinable == false then --// Debounce
            coinable = true --// Part is now untouchable
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 25 --// Gives the cash
            wait(20) --// Waits 20 seconds
            coinable = false --// Part is touchable again
        end
    end
end)

You needed the "hit" as a parameter because it helps with finding what touched it. You also have to find the player and all that before you can activate the debounce. I am not sure why, I am a new programmer as well.

I cant really explain i,v in pairs() very well, but here is the shortest short of it.

i,v in pairs(game.Players:GetPlayers()) if v then (v is the getting players.) (In my experience, you can change i or v to whatever you want.)

Hope some of this helps.

Ad

Answer this question