Button script doesn't work with remote event

I made it a button with a remote event instance, but it isn’t doing. There is an example of the scripts:

Button script:

local p = script.Parent
local controlEvent = p.ControlEvent
local RBControlEvent = p.RBControlEvent

local SRBtn = p["2ndRinseBtn"]
local DryBtn = p.DryBtn
local KillSwitch = p.KillSwitchBtn
local RinseBtn = p.RinseBtn
local RBBtn = p.RotatingBrushesBtn
local SoapBtn = p.SoapBtn

local SRInd = SRBtn.Indicator
local DryInd = DryBtn.Indicator
local KillSwitchInd = KillSwitch.Indicator
local RinseInd = RinseBtn.Indicator
local RBInd = RBBtn.Indicator
local SoapInd = SoapBtn.Indicator

local touchesChildren = p.Touches:GetChildren()

local touches = p.Touches

local SRAction = touches["2ndRinseAction"]

SRBtn.Button.ClickDetector.MouseClick:Connect(function(plr)
	controlEvent:FireClient(plr, SRAction, SRInd)
end)

Event Script:

local p = script.Parent

local cEvent = p.ControlEvent
local rbcEvent = p.RBControlEvent

cEvent.OnServerEvent:Connect(function(plr, act, ind)
	local player = plr
	local indicator = ind
	local action = act
	
	if action.script.Enabled == false then
		indicator.Material = Enum.Material.Neon
		indicator.PointLight.Enabled = true
		action.script.Enabled = true
		print(player.Name .. " is enabled ".. act.Name)
	else
		ind.Material = Enum.Material.SmoothPlastic
		ind.PointLight.Enabled = false
		action.script.Enabled = false
		print(player.Name .. " disabled ".. act.Name)
	end
end)

How do I make the button that works with remote events?

Ur firing the client not the server, u cant put a local script in the click detector

ClickDetector events fire on both the client and the server, even when FilteringEnabled is on. Since a LocalScript will only run if descends from a Player or Player’s Character , it’s usually not useful to put a LocalScript inside a ClickDetector (since the script won’t run, or the object won’t be clickable). If you need a LocalScript to detect ClickDetector events, StarterPlayerScripts may be a better place instead.

In the client script you could try this:

cEvent.OnServerEvent:Connect(function(act, ind)
local player = game.Players.LocalPlayer

because when its fired on the client it will only run for that player, because in the server it was already told. so you dont have to put again the plr parameter.

1 Like

Yes, but I removed the keyword “plr” and renamed “FireClient” to FireAllClient, but it doesn’t work either. So, I edited my script:

SRBtn.Button.ClickDetector.MouseClick:Connect(function()
	controlEvent:FireAllClients(SRAction, SRInd)
end)

How can I try this with other fire events which is a server?

No, you dont have to change the fireclient to fireallclients, it was alright. Change it and try again
Remember putting the player argument in fireclient

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