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

How to get the values one time when teleporting?

Asked by 8 years ago

Script works fine, idk if it did copy correct because am right now on the phone. But their is a problem when the player touches they get teleported but the about the values they get it sometimes twice or 3 times when it need be one.

Does someone know how to fix this? That when a player touches they just get teleported and get the values once at time bc its not good for my game that they get the wins twice or 3 times.

Thank you

 local ting = 0

function onTouched(hit)
    if ting == 0 then
    ting = 1
    check = hit.Parent:FindFirstChild("Humanoid")
    v=hit.Parent:FindFirstChild("Torso")

    if check ~= nil then

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

        if stats ~= nil then
            local TWEE = stats:findFirstChild("Exp")
            local VIER = stats:findFirstChild("Wins")
            local ZEVEN = stats:findFirstChild("Coins")

                TWEE.Value = TWEE.Value + 10
                VIER.Value = VIER.Value + 1
                ZEVEN.Value = ZEVEN.Value + 2
        end
        if (v~=nil) then 
        v.CFrame = CFrame.new(-37.161, 43.18, 72.114)
        else print("No Teleport")
        end
    end

    ting = 0
    end
end

script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

I believe the issue here is that your debounce, ting, is being switched back to ready too quickly.

On line 28, add a wait() or wait(.5), and see if that fixes your problem.

0
I will try thanks i already tried a wait put got it in the wrong line tomorrow i try yours fix. Thanks! minetrackmania 186 — 8y
Ad

Answer this question