Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 5 days ago
Edited 5 days 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 Diezel_1K 73 — 5d
0
also, #players doesn't have a name. Do players[1].Name instead. Diezel_1K 73 — 5d
0
:| Noob mistake. Should've realized that!! EliteMarata 19 — 5d
0
Also, the #players one worked so... Idk EliteMarata 19 — 5d
View all comments (15 more)
0
New error... EliteMarata 19 — 5d
0
"ServerScriptService.IfPlayer1onteamthem:6: bad argument #1 to 'pairs' (table expected, got nil)" EliteMarata 19 — 5d
0
team is a non-existent variable, I think you mean teams Diezel_1K 73 — 5d
0
Ok then. EliteMarata 19 — 5d
0
Did you update your code to what it currently is? DinozCreates 423 — 5d
0
Oh I'll do that. EliteMarata 19 — 5d
0
Updated it. EliteMarata 19 — 5d
0
I also dont know HOW #players.Name could be working, # returns the length of a table. So its essentially 1.Name. DinozCreates 423 — 5d
0
New error... "ServerScriptService.IfPlayer1onteamthem:10: attempt to index local 'playertochange' (a string value)" EliteMarata 19 — 5d
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 423 — 5d
0
Well, I am like a noob so uhhh Idk what string means but I wish I did... OOF sorry. EliteMarata 19 — 5d
0
You're trying to change the player's name to a team... You should really look over your code. :/ TheeDeathCaster 2136 — 5d
0
My gosh am I dumb.... I realize that completely now... EliteMarata 19 — 5d
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. Diezel_1K 73 — 5d
0
Thank you so much. Someone leave a answer and I will mark it as answered! EliteMarata 19 — 5d

Answer this question