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

Why doesn't this teleport-to-checkpoint script not work?

Asked by 5 years ago
Edited 5 years ago

You can read the comments at the end of the script(where the statement didn't work) for more information, no errors. It doesn't print anything even when the player has stage 2.

enabled = true
n = script.Parent

script.Parent.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") and enabled == true then
        local plr = game.Players[part.Parent.Name]
        local stats = plr.leaderstats
        local stage = stats.Stage
        if stage.Value == n.Name-1 then
            stage.Value = (n.Name)
        end
    end
end)
-- above is working fine

game.Players.PlayerAdded:Connect(function(player)
    wait(0.25)
    -- cant do waitforchild cause it causes infininte yeilds all the time
    local stats = player.leaderstats
    local character = player.Character
    local stage = stats.Stage
    print(stats.Name.." loaded") -- This loaded
    print(stage.Name.." loaded") -- This loaded too
    wait()
    if stage.Value == n.Name then -- This doesn't work! Plus n.Name is "2"
        print("test sdas") -- This doesn't print! EVEN if the player has stage 2!
        character.HumanoidRootPart.CFrame = CFrame.new(n.Position)
    end
end)
0
try using "2" instead of n.Name Abandion 118 — 5y
0
i wanna make it easier by changing part name mudathir2007 157 — 5y

1 answer

Log in to vote
0
Answered by
jaschutte 324 Moderation Voter
5 years ago

I think I found your error: if stage.Value == n.Name then You are trying to compare a number with a string, and that will always return false. Try:

if stage.Value == tonumber(n.Name) then
    --your code.
end

And if you are wondering why it does work here:

if stage.Value == n.Name-1 then
    stage.Value = (n.Name)
end

That's because when you have a string like "21" and then do a mathmatical operation on it. Roblox will automaticly detect that it is a number and it will continue without error.

I hope this fixed your problem!

Ad

Answer this question