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

Help with leaderboard and spawning?

Asked by 8 years ago

I am using my own old broken obby script that didn't work and a derivation of a script from Code Theorem on youtube. The problem is I have the same error which is the player not going where I want them to.

I have parts which are number name based on the fact that if touched and higher than plr.leaderboard.Stage.Value they're name will become the value of Stage in the leaderboard. I also have a level name value which works as well. My problem is when I attempt to make the player spawn at the part with the name equal to Stage's value and with the string value that equals level's value.

Please tell me what I am doing wrong:

lead = nil
Stag = nil
Stag2 = nil

game.Players.PlayerAdded:connect(function(plr)
    lead = Instance.new('Model')
    lead.Name = "leaderstats"
    lead.Parent = plr

    Stag = Instance.new('IntValue')
    Stag.Name = "Stage"
    Stag.Parent = lead
    Stag.Value = 0

    Stag2 = Instance.new('StringValue')
    Stag2.Name = "Level"
    Stag2.Parent = lead
    Stag2.Value = "Not Included"
    plr.CharacterAdded:connect(function(chr)
        local spawn = script.Parent[""..plr.leaderstats.Stage.Value]
        if spawn.StringVal.Value == Stag2.Value then
            chr:MoveTo(spawn.Position)
        end
    end)
end)

for i,v in pairs(script.Parent:GetChildren()) do
    if v.ClassName == "Part" then
        v.Touched:connect(function(hit)
            if Stag.Value < tonumber(v.Name) then
                Stag.Value = tonumber(v.Name)
                Stag2.Value = v.StringVal.Value
            end
        end)
    end
end

lines to emphasize:

plr.CharacterAdded:connect(function(chr)
        local spawn = script.Parent[""..plr.leaderstats.Stage.Value]
        if spawn.StringVal.Value == Stag2.Value then
            chr:MoveTo(spawn.Position)
        end
    end)
0
@TSP273 Tried replacing chr:MoveTo(spawn.Position) with chr.Torso.CFrame = CFrame.new(Vector3.new(0, 3, 0))+spawn.Position, still not working do you see an error? MrDefaultMan 113 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Lines 20-23:

local spawn = script.Parent[""..plr.leaderstats.Stage.Value]
if spawn.StringVal.Value == Stag2.Value then
    chr:MoveTo(spawn.Position)
end

You're only going to move the player if that statement is true.

Which when the player is added, it's not. From what I can tell.

Because: Stag2.Value = "Not Included", Is not equal to I'm going to guess 0 at the time..

Ad

Answer this question