I've encountered a problem with my script

So I have a script that is a voting system I’m working on for choosing topics and for some reason the client clearly shows that an object exists but whenever I pass it through a remote event it prints nil?

Client Script:

button.MouseButton1Click:Connect(function()
	print(button)
	VoteButtonEvent:FireServer(button)
end)

Rs.ChangeVoteText.OnClientEvent:Connect(function(buttonName)
	print(buttonName)
	if buttonName == script.Parent then
		VoteInt.Value += 1
		text.Text = tostring(VoteInt.Value)
	end
	
end)

Prints the instance the first time then prints nil

Server Script:

	Rs.VoteButton.OnServerEvent:Connect(function(player, button)
		print(button)
		Rs.ChangeVoteText:FireAllClients(button)
	end)

prints nil

also I would like to add that I have checked and all of this script is running just the if statement is false (because its nil)

1 Like

It’s likely that the button only exists on the client side, rather than the existing on both the client and the server.

I would recommend passing the name of the button (or the text) through the remote event, then processing that instead of the button object.

1 Like

Warning user your code is a crimethink against Ministry of Luau please submit reeducation report.
Crimethink against ministry of server is ungood.
button is unpersoned and never ever existed you cannot access it.

2 Likes

Yeah, exactly.

I also noticed on the OnClientEvent function that it checks if the ButtonName is equal to the script’s parent which will always be false. Instead, it should be if buttonName == script.Parent.Name

1 Like

Thank you! this ended up working but I was a bit confused cause I had tried to do that right before I made it to an instance instead but I fixed a few other things that were wrong so thats probably why :frowning: .

1 Like

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