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

Leadstats Won't Show Up & No Errors?

Asked by 4 years ago

I have a script, but it won't show the leaderstats.

function oa(object)
    local player = game.Players:playerFromCharacter(object)
print(error)
:Destroy()
    if player ~= nil then
        local ls = player.leaderstats
        local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
        print("obby")
        object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0)
        wait()
        object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0)
    end 
end

function oe(object)
    if object.className == "Player" then
        local ack = Instance.new("IntValue")
        ack.Name = "leaderstats"
        local ack2 = Instance.new("IntValue")
        ack2.Name = "Stage"
        ack2.Value = 1
        ack2.Parent = ack
        ack.Parent = object
    end 
end

game.Players.ChildAdded:connect(oe)
game.Workspace.ChildAdded:connect(oa)

I am like half asleep so if It is obvious, sorry. :/

3 answers

Log in to vote
1
Answered by 4 years ago

You should be using Players.PlayerAdded and Player.CharacterAdded for stuff like this. I assume you might be testing it in-studio without starting up a server.

There's a usual case where the player joins before the server scripts run. This means events like ChildAdded and PlayerAdded miss that player's join. You want to run the function through all players in-game before connecting the event or just test through starting a server or playing the actual place.

local PlayerAdded = function(player)

    --leaderstat stuff

    local CharacterAdded = function(character)
        --character stuff + you have access to leaderstats!
    end
    CharacterAdded(player.Character or player.CharacterAdded:Wait())
    --applies the function to the first character added
    player.CharacterAdded:Connect(CharacterAdded)
    --applies the function to further character respawns

end)

for _, player in next, game.Players:GetPlayers() do
    PlayerAdded(player)
end
--applies the function to all players in-game
game.PlayerAdded:Connect(PlayerAdded)
--applies the function to all arriving players
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Oops, sorry the error was the :Destroy(); I wrote it in the wrong script. Sorry for wasting your time. :>

Log in to vote
-2
Answered by 4 years ago
game.Players.PlayerAdded:Connect(function(player)
    local ack = Instance.new("Folder",player)
        ack.Name = "leaderstats"
        local ack2 = Instance.new("IntValue",ack)
        ack2.Name = "Stage"
        ack2.Value = 1
end)

Answer this question