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

Why is my Chat Command not working?

Asked by
Seraine 103
8 years ago

When the player say ":D", an image should appear above the player's head. The image is made up from a BillboardGui, which I put inside the script.

function onChatted(msg, speaker)

    source = string.lower(speaker.Name)
    msg = string.lower(msg)

    if (msg == ":D") then 
        local laugh = script.Laugh:Clone() -- The BillboardGui is called "Laugh"
        laugh.Parent = speaker.Character.Head
        wait(2)
        laugh:remove() -- image should remove after 2 seconds
    end
end

function onPlayerEntered(newPlayer) 
    newPlayer.Chatted:connect(function(msg) onChatted(msg, newPlayer) end) 
end

game.Players.ChildAdded:connect(onPlayerEntered)

When I say ":D" in game nothing happens, but when I dragged the BillboardGui inside the player's head in studio mode, the image appears like it should. Help please?

Thanks.

2 answers

Log in to vote
1
Answered by 8 years ago

Have you set the Adornee of the billboard gui?

It looks like your script is fine, but I don't see you setting it's Adornee. Here;

local laugh = script.Laugh
laugh:clone().Parent = speaker.Character.Head
laugh.Adornee = speaker.Character.Head
wait(2)
speaker.Head.Laugh:destroy()

~TDP

0
Didn't know Adornee was needed ;P Seraine 103 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

Try this:

game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
    if msg == ":D" then 
        local laugh = script.Laugh
        laugh:clone().Parent = speaker.Character.Head
        wait(2)
        speaker.Head.Laugh:destroy()
    end
end)
end)


Answer this question