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

What is wrong with my disco script?

I think this is correct but its not working...

function onChatted(msg, recipient, speaker) --Function for msg

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

if (msg == "disco") then	
	
	script.Parent.Color = Color3.new(math.random(), math.random(), math.random())
wait(0.5)
end
	
end

2 comments

3

You don't have a connection line for your function.

1

As it is, this function will never run. Please look up the Chatted event on the wiki.

1 answer

As RedCombee and Perci1 said, you have to add a connection line at the end. However, there are more than just those problems, so here is a fixed script.

function onPlayerAdded(player) --You need to also do this
	function onChatted(msg, recipient) --Speaker is not a valid property of Chatted
		local source = string.lower(player.Name) --This line is unnecessary unless you are using it later in the code. If you are not, you don't need it.
		msg = string.lower(msg)
		if msg == "disco" then --You don't need the parenthesis   
			script.Parent.Color = Color3.new(math.random(0, 255), math.random(0, 255), math.random(0, 255)) --You need to do the math.random values. If this is in a part, use BrickColor.Random() instead.
			wait(0.5)
		end
	end
	player.Chatted:connect(onChatted) --This is the connect line for the onChatted function
end
game.Players.PlayerAdded:connect(onPlayerAdded)

I hope this helps!

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