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

Why can I not seem to use this value from an array when selecting a player in my code?

Asked by 3 years ago
Edited 3 years ago

I am trying to make a script that will make the first player who joins my game be able to walk faster. This is the code:

game.Players.PlayerAdded:Connect(function(player)

    local plylist = {game.Players:GetPlayers()}

    if plylist[2] == nil then

        local onlyply = plylist[1]

        game.Players.onlyply.character:FindFirstChild("Humanoid").WalkSpeed = 150

    end

end)

However, when ever I run this, Roblox gives me this error...

'onlyply is not a valid member of Players "Players"'

Can someone tell me what am I doing wrong and how to I fix this?

0
In line 9 you are searching onlyply in game.Players which does not exists. Since you already have onlyply set as a variable you can just delete the game.Players in line 9 and it should run Asrzybo 0 — 3y
0
It worked! Thanks. That helped a lot. EvilWray 2 — 3y

Answer this question