Help with remote event

hey guys, i have this “state” variable i made to be sent to the script. im just having trouble with the state tbh. i appreciate any help. :slight_smile:

local script:

	yes.MouseButton1Click:Connect(function()
	local state = "yes"
	plrcheckEvent:FireServer(myPlr, state)
	end)

	no.MouseButton1Click:Connect(function()
		local state = "no"
plrcheckEvent:FireServer(myPlr, state)
	end)

script:

plrcheckEvent.OnServerEvent:Connect(function(myplr, state)
	plrchoiceUI.Enabled = false

	--if clicked no
	if state == "no" then
		if selectedButton then
			selectedButton.BackgroundColor3 = unselectedColor
		end
	end

	--if clicked yes
	if state == "yes" then
		if selectedButton then
			selectedButton.BackgroundColor3 = unselectedColor
		end
		if selectedButton then
			local findPlr = plrs:FindFirstChild(selectedButton.Text)
			if findPlr and findPlr ~= myplr then
				if 	findPlr.Character.Humanoid.Health > 0 then
					findPlr.Character.Humanoid.Health = 0
				end
			end
		end
	end
end)

You do not need to pass the player through RemoteEvent:FireServer; the server already knows the player who fired it. Change it to:

plrcheckEvent:FireServer(state)

and keep the OnServerEvent the same:

plrcheckEvent.OnServerEvent:Connect(function(myplr, state)
1 Like

This will not work:

plrcheckEvent.OnServerEvent:Connect(function(myplr, state)

In your server script you must declare “player” in all cases as is default

plrcheckEvent.OnServerEvent:Connect(function(player, state)

There is no need to declare player on the client, just “state”

plrcheckEvent:FireServer(state)
1 Like

hey omega, thanks for ur help. i keep forgetting about that. i fixed that.

just one issue, this part isn’t changing the colour of my button to grey when i click no.

	if state == "no" then
		if selectedButton then
			selectedButton.BackgroundColor3 = unselectedColor
		end
	end

dc7a8a64f8f7b8068301e0434cf3dd7d

EDIT: NVM. i made an error in the client script. tysm for ur help omega!

hey breno, thank u so much for ur help. i understand now. have a great day! :smiley:

1 Like

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