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

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

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


3 comments

0

is this a localscript or a script ? where is it located and :remove is deprecated

0

Message is also deprecated

0

Test using print if that works already

2 answers

✓ Accepted answer

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.

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!

6 comments

0

btw you can just do game.Players.PlayedAdded:Connect(Joined)

0

True, I like to set it up like that

0

I got an error in the code: " 11:30:21.503 - PlayedAdded is not a valid member of Players "Players""

0

its a mispelling, it should be "PlayersAdded". and also, do what VerdommeMan said.

0

When a fricken type makes me lose my chance of getting my answer accepted

0

TYPO* WTH

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