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

How do I get this script to work once per player?

Asked by 9 years ago

Ok so I made a script where you touch a part and you get a Point in the leaderboard. I called the Points Stars. How do I get this script to work once for each player. For example a guy gets the star and in the leaderboards it says he has 1 star. Then he goes up to it again and he doesn't get another star from that one because he already has it. Please help I kept trying but when I did it just didn't work! :(

local ting = 0 --debouncer

function onTouched(hit)

    if ting == 0 then --debounce check
    ting = 1 --activate debounce
    check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button
    player = hit.Parent

    if check ~= nil then --If a human is found, then

        local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
        local stats = user:findFirstChild("leaderstats") --Find moneyholder

        if stats ~= nil then --If moneyholder exists then

            local cash = stats:findFirstChild("Stars") --Get money

            cash.Value  = cash.Value +1 --increase amount of money by the number displayed here (1)
            wait(1)
            check.Health = 0
            wait(4) --wait-time before button works again

            end
        end

    end

    ting = 0 --remove debounce
    end

script.Parent.Touched:connect(onTouched)
0
You could always add a value to the players, then if they touch it, it makes it true. Or something.. Tempestatem 884 — 9y
0
Hmm but if I make the star insert a value there will be lots of values in your character and it could glitch. I want it to go by the player's name who touched it and then if they touch it again it just adds 0. flamenathan327 20 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Add a value to the players, example;

If you add a value to the players, and they touch the 'Star', it makes it true.

0
Oh and also I found a glitch where you get lots of stars when touching the part that supposed to give you one. I even made it kill too but that didn't help. Please help me! flamenathan327 20 — 9y
Ad

Answer this question