Ad
Log in to vote
1

attempt to call method 'Kick' (a nil value)?

Asked by
pwx 1546 Moderation Voter
3 years ago

I recently got this error whilst practising splitting up strings into commands (I understand this probably isn't the best method when splitting up strings, but it's a start).

Anyway, I get this error:

https://gyazo.com/31c6308b205160edc320c178eb3b55a5

I'm not entirely sure what's wrong with it, either way here is the entire script:

https://gyazo.com/50e43342b40e614760a568e62b0c0b76

Could any of you explain what's wrong? Thank you.

0
You're calling it from the name of the player and not the player itself. DeceptiveCaster 3761 — 3y
0
The problem is the line: local target, reason = string.match(Message, " (.-) (.+)") since both target and reason come back as nil SerpentineKing 3885 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

The return value of the getPlayer function is a table of players, and not a player. You can't call Kick on a table. There cannot be several players with the same name, so you should just return the first match.

Instead of table.insert(returned, v) just return v.

0
Alright. Thank you. pwx 1546 — 3y
Ad

Answer this question