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

Help with getting players in server?

Asked by 8 years ago
-- NinjoOnline --

local sword2level = 5
local sword3level = 10
local sword4level = 20

print("0")

while wait() do
    for _, player in pairs(game.Players:GetPlayers()) do
        if player then
            print("1")
            local shop = player:WaitForChild("Shop")
            if shop then
                print("2")
                local stats = player:WaitForChild("leaderstats")
                if stats then
                    print("3")
                    local level = stats:WaitForChild("Level")
                    if level then
                        print("4")
                        level.Changed:connect(function(playerLevel)
                            print("5")
                            if playerLevel >= sword2level then
                                print("6")
                                shop:WaitForChild("KnightsSword").Value = true
                            elseif playerLevel >= sword3level then
                                shop:WaitForChild("ShadowDancer").Value = true
                            elseif playerLevel >= sword4level then
                                shop:WaitForChild("OrcBlade").Value = true
                            end
                        end)
                    end
                end
            end
        end
    end
end

The script is located inside serverscriptstorage and is a serverscript. It prints 0, but thats it. Please help.

1 answer

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
8 years ago

Your script should be put into serverscriptservice, not serverstorage. You shouldn't be using :WaitForChild() if you are checking to see if an item exists. :WaitForChild() will wait forever until that item exists, even if it will never exist. If you are checking to see if an item exists, then use :FindFirstChild(), if you know an item will eventually exist and hasn't been created/loaded yet, then use :WaitForChild(), otherwise your script will wait forever.

This should fix your problems.

local sword2level = 5
local sword3level = 10
local sword4level = 20
local players = game:GetService'Players' -- If the player service doesn't already exist
print("0")

while wait() do
    repeat wait() until players.NumPlayers >= 1 -- Wait until there is 1 or more players in the game
    for _, player in pairs(players:GetPlayers()) do
        print("1")
        local shop = player:FindFirstChild("Shop")
        if shop then
            print("2")
             local stats = player:FindFirstChild("leaderstats")
            if stats then
                print("3")
                local level = stats:FindFirstChild("Level")
                if level then
                    print("4")
                    level.Changed:connect(function(playerLevel)
                                    print("5")
                                    if playerLevel >= sword2level then
                                        print("6")
                                        shop:WaitForChild("KnightsSword").Value = true
                                    elseif playerLevel >= sword3level then
                                        shop:WaitForChild("ShadowDancer").Value = true
                                    elseif playerLevel >= sword4level then
                                        shop:WaitForChild("OrcBlade").Value = true
                                    end
                                end)
                end
            end
        end
    end
end




0
it is in erverscriptstorage NinjoOnline 1146 — 8y
0
There is no serverscriptstorage, just ServerScriptService and ServerStorage. I presume you mean ServerScriptService? 4Bros 550 — 8y
0
It should be in ServerScriptService, else (if it's in ServerStorage) the script wouldn't run. Redbullusa 1580 — 8y
0
oh yeah sorry, i meant it was in the serverscriptservice :P NinjoOnline 1146 — 8y
Ad

Answer this question