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

Messaging Service, Attempt to index a nil value on line 17?

Asked by 5 years ago

I need help, I've been looking for hours on how to fix this, I've also asked a tried to ask a few people with no success, the script I've made is for chat tags, but they don't work at all, the error is in the question title, I am very tired when I write this so don't mind my terrible English and whatnot here is the script. https://pastebin.com/BYid0YrX

Thanks in advance, Destroyer1234x.

0
Put your script in this thread in code tags, please. Sonnenroboter 336 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I think this is because of the delay between the moment the player joins and until ROBLOX makes them a Speaker.

Instead try binding your function to SpeakerAdded in ChatService this way whenever your function runs, the speaker will always be there

One tip for you though is to use assert(), it's a good debugging tool and really easy to use. Basically if the condition is false it prints what you told it to and breaks, so like this:

assert(true,"This will never print because the condition is always true")
assert(false,"This will always print because the condition is always false")
print("This will not print because when assert if false, it breaks")
plr = game.Players:FindFirstChild("someReallyWeirdName")
assert(plr,"If this prints then the player doesn't exist and if the code runs it will error")
0
Another question, what happens when an assert() is true? Does it error or stop the rest of the code? Destroyer1234x 52 — 5y
0
Also i've tried the speakeradded thing, unfortunatly it still doesnt work returning another error. Destroyer1234x 52 — 5y
Ad

Answer this question