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

Why does it show this error when I run my sword fight game?

Asked by 5 years ago
Edited 5 years ago

Code : (updated)x2

local teams = game:GetService("Teams"):GetTeams()
local teamss = game:GetService("Teams")

wait(5)

for _, team in pairs(teams) do
    local players = team:GetPlayers()
    if players[1] then
        local playertochange = players[1].Name
        playertochange.Team = (teamss:FindFirstChild("Lobby"))
    end
end
0
close parentheses at the end of line 10 Trew86 175 — 5y
0
also, #players doesn't have a name. Do players[1].Name instead. Trew86 175 — 5y
0
:| Noob mistake. Should've realized that!! EliteMarata 34 — 5y
0
Also, the #players one worked so... Idk EliteMarata 34 — 5y
View all comments (15 more)
0
New error... EliteMarata 34 — 5y
0
"ServerScriptService.IfPlayer1onteamthem:6: bad argument #1 to 'pairs' (table expected, got nil)" EliteMarata 34 — 5y
0
team is a non-existent variable, I think you mean teams Trew86 175 — 5y
0
Ok then. EliteMarata 34 — 5y
0
Did you update your code to what it currently is? DinozCreates 1070 — 5y
0
Oh I'll do that. EliteMarata 34 — 5y
0
Updated it. EliteMarata 34 — 5y
0
I also dont know HOW #players.Name could be working, # returns the length of a table. So its essentially 1.Name. DinozCreates 1070 — 5y
0
New error... "ServerScriptService.IfPlayer1onteamthem:10: attempt to index local 'playertochange' (a string value)" EliteMarata 34 — 5y
0
You're trying to change a string value to whatever value type lobby is, which wont work. You need to directly reference another string on the second half of line 10. DinozCreates 1070 — 5y
0
Well, I am like a noob so uhhh Idk what string means but I wish I did... OOF sorry. EliteMarata 34 — 5y
0
You're trying to change the player's name to a team... You should really look over your code. :/ TheeDeathCaster 2368 — 5y
0
My gosh am I dumb.... I realize that completely now... EliteMarata 34 — 5y
0
You don't need to get the name of the player. Just set player[1].Team. The name is just a string value and doesn't have a Team property. Trew86 175 — 5y
0
Thank you so much. Someone leave a answer and I will mark it as answered! EliteMarata 34 — 5y

Answer this question