Help with firing event from button (local script)

hi, im trying to make it so when you press the button, it will activate an event. but when i press the button, nothing happens. (fyi, when i join the game im teamed another team, and i manually team myself to the brown coloured team afterwards)

local clickDetector = script.Parent.ClickDetector
local remoteevent = game.ReplicatedStorage.CannonPrep
debounce = false
local function onClicked(player)
	if not debounce then
	if player.TeamColor == BrickColor.new("Brown") then
		print("passed check 1") --it does not print
		debounce = true
		script.Parent.Sound:Play()
		remoteevent:FireServer()
		wait(35)
		debounce = false
		end
	end
end

clickDetector.MouseClick:Connect(onClicked)

how could i fix this?

LocalScripts only run when parented to a specific set of containers. Refer to this for said containers

Now, as for Scripts with RunContext set to Client, I believe they will run no matter where they are parented. Though I have never used normal scripts this way personally, so I could be wrong.

So you could either try changing the LocalScript to a normal script with RunContext set to Client, or, changing this to just a normal server script and changing the content of the script accordingly.

1 Like

oh yo it worked when i made it a normal script and changed it to client, thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.