Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my chat script having this error message?

I'm making this custom chat thingy and my script got a weird error. here is my script: (its in serverscrptservice)

    player.Chatted:connect(function(msg)
  local    m = Instance.new("Hint")
m.Parent = game.Workspace
m.Text = (msg)
wait(1)
if player.Chatted:connect(function(msg) 
m:Destroy()
end)
    end) -- expected 'then' got end
end)

I changed end) to end but it is still not working so I changed it back. any ideas? Thanks for reading! I also added then to it but then it said

Expected identifier got 'then'

5 comments

0

Why do you have an 'if on line 6?

0

I want it to detect if another person chatted, then destroy the current message so the messages won't build up on each other.

1

I'll tell you - that's definitely not the way to do it.

0

Then, what is?

0

Also, it's not creating a hint every time someone chats.

1 answer

You can't use conditional statements (if and then statements) with functions. Also, what the error meant is your forgot to put a "then." Here's a better version of your script:

player.Chatted:connect(function(msg)
if not workspace:FindFirstChild("PlayerMessageHint") then
local m = Instance.new("Hint", workspace)
m.Name = "PlayerMessageHint"
m.Text = msg
elseif workspace:FindFirstChild("PlayerMessageHint") then
workspace:FindFirstChild("PlayerMessageHint").Text = msg
end
end)

6 comments

0

Thanks! i'll test it.

0

doesn't do anything.

0

Did you define "player"?

0

yep.

0

oh you forgot to capitalize the workspace.

0

This discussion is preserved as it was. New answers, comments, and votes are closed.