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

My script does not work. What did I do wrong?

Asked by 4 years ago
Edited 4 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Before you act like "You put in x but don't understand x? Well I got some stuff from a tutorial on the Dev hub and the rest I made myself. Whenever I put in the chat "spoopy" it doesn't work. What am I doing wrong"?

local announcer = Instance.new("Message")
local function Joined(plr)
    -- Everytime they chat, we want to know
    plr.Chatted:Connect(function(msg)
        if msg == "spoopy" then -- Aha, that's our cue
            game.Lighting.Theboss:clone().Parent = game.Workspace
            announcer.Parent = game.Workspace
            announcer.Text = "Uh oh someone summoned something weird!"
            wait(3)
            announcer:remove()
        end
    end)
end


0
is this a localscript or a script ? where is it located and `:remove` is deprecated VerdommeMan 1479 — 4y
0
Message is also deprecated VerdommeMan 1479 — 4y
0
Test using print if that works already VerdommeMan 1479 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The way you are using functions is not needed, however I am not saying it is bad practice. The way you are messing up is that you are never connecting the joined function to PlayerAdded.

game.Players contains a RBXScriptSignal named PlayerAdded. You need to use the Connect function of it and connect it to the Joined function.

game.Players.PlayerAdded:Connect(Joined)

Documentation can be found here for RBXScriptSignals and here for PlayerAdded.

Hope this helps.

Also, both Remove and Message are deprecated, so please look into that.

Edit: This can also be heavily spammed. Consider adding a debounce or some sort of whitelisting system to it. As of right now, it will allow you to say spoopy whenever you want and that boss will spawn. The first time it will say the message, however it will destroy your Message object, resulting in you being unable to see the message again, yet it will still spawn another boss.

Ad
Log in to vote
0
Answered by 4 years ago

remove and message is deprecated, so is hint in case you saw that somewhere. Also you didn't call Joined.

local announcer = Instance.new("Message")
local function Joined(plr)
    -- Everytime they chat, we want to know
    plr.Chatted:Connect(function(msg)
        if msg == "spoopy" then -- Aha, that's our cue
            game.Lighting.Theboss:clone().Parent = game.Workspace
            announcer.Parent = game.Workspace
            announcer.Text = "Uh oh someone summoned something weird!"
            wait(3)
            announcer:remove()
        end
    end)
end

game.Players.PlayedAdded:Connect(function(p)
    Joined(p)
end)

I would replace the message with prints so you can see them in the output.

local function Joined(plr)
    -- Everytime they chat, we want to know
    plr.Chatted:Connect(function(msg)
        if msg == "spoopy" then -- Aha, that's our cue
            game.Lighting.Theboss:clone().Parent = game.Workspace
            print("Uh oh someone summoned something weird!")
        end
    end)
end

game.Players.PlayedAdded:Connect(function(p)
    Joined(p)
end)

If this helps then please click the Accept button, if it doesn't, write in the comments, Enjoy!

0
btw you can just do `game.Players.PlayedAdded:Connect(Joined)` VerdommeMan 1479 — 4y
0
True, I like to set it up like that greatneil80 2647 — 4y
0
I got an error in the code: " 11:30:21.503 - PlayedAdded is not a valid member of Players "Players"" Velocityok 36 — 4y
0
its a mispelling, it should be "PlayersAdded". and also, do what VerdommeMan said. FirewolfYT_751 223 — 4y
View all comments (2 more)
0
When a fricken type makes me lose my chance of getting my answer accepted greatneil80 2647 — 4y
0
TYPO* WTH greatneil80 2647 — 4y

Answer this question