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.

01function oa(object)
02    local player = game.Players:playerFromCharacter(object)
03print(error)
04:Destroy()
05    if player ~= nil then
06        local ls = player.leaderstats
07        local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
08        print("obby")
09        object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0)
10        wait()
11        object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0)
12    end
13end
14 
15function oe(object)
View all 28 lines...

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.

01local PlayerAdded = function(player)
02 
03    --leaderstat stuff
04 
05    local CharacterAdded = function(character)
06        --character stuff + you have access to leaderstats!
07    end
08    CharacterAdded(player.Character or player.CharacterAdded:Wait())
09    --applies the function to the first character added
10    player.CharacterAdded:Connect(CharacterAdded)
11    --applies the function to further character respawns
12 
13end)
14 
15for _, player in next, game.Players:GetPlayers() do
16    PlayerAdded(player)
17end
18--applies the function to all players in-game
19game.PlayerAdded:Connect(PlayerAdded)
20--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
1game.Players.PlayerAdded:Connect(function(player)
2    local ack = Instance.new("Folder",player)
3        ack.Name = "leaderstats"
4        local ack2 = Instance.new("IntValue",ack)
5        ack2.Name = "Stage"
6        ack2.Value = 1
7end)

Answer this question