Basically I'm designing a hotel-like system where it sends a message to the server and then to all players that a room has been taken. It works but only for the first button, and I can't figure out how to tell the server which button was pressed.

Localscript:

r201.MouseButton1Down:Connect(function()
		if roombought == false then
			roombought = true
			rt:FireServer(r201)
		elseif roombought == true then
			r201.Text = "X"
		end
	end)
	r202.MouseButton1Down:Connect(function()
		if roombought == false then
			roombought = true
			rt:FireServer(r202)
		elseif roombought == true then
			r202.Text = "X"
		end
	end)
	r301.MouseButton1Down:Connect(function()
		if roombought == false then
			roombought = true
			rt:FireServer(r301)
		elseif roombought == true then
			r301.Text = "X"
		end
	end)
	r302.MouseButton1Down:Connect(function()
		if roombought == false then
			roombought = true
			rt:FireServer(r302)
		elseif roombought == true then
			r302.Text = "X"
		end
	end)

ServerScript:

rt.OnServerEvent:connect(function(player, r201,r202,r301,r302)
	print "testserver"
	if r201 then
		local tag = Instance.new("StringValue")
		tag.Name = "StringValue"
		tag.Parent = r201
		rtc:FireAllClients()
	end
	if r202 then
		local tag = Instance.new("StringValue")
		tag.Name = "StringValue"
		tag.Parent = r202
		rtc:FireAllClients()
	end
	if r301 then
		local tag = Instance.new("StringValue")
		tag.Name = "StringValue"
		tag.Parent = r301
		rtc:FireAllClients()
	end
	if r302 then
		local tag = Instance.new("StringValue")
		tag.Name = "StringValue"
		tag.Parent = r302
		rtc:FireAllClients()
	end
end)

I'm trying to tell the serverscript via arguments (which I assume I'm using wrong) which room was bought by putting the value in the parenthesis of "fireserver" in the localscript. Then I'm checking to see if it was indeed put in the arguments, which should fire the correct part of the serverscript, which then sends it to another localscript (thats how it's supposed to work in my head, anyways). Like I said, the 1st button works totally fine and when a 2nd player presses the 2nd button, it too works. But if you skip one the localscript doesn't fire to the correct part of the serverscript.

That may have been super confusing, but any and all help would be appreciated!

5 comments

0

On the server you're expecting four other parameters when you are only sending one extra parameter. since you are only firing 1 parameter 'r201' will always exist. Instead, send the name of the button that you want to click such as "r201", "r202" etc. and then send the instance as the second parameter. Your server function should now look like:

0

rt.OnServerEvent:connect(function(player, buttonName, button)

0

Also, if you are adding something to the player's gui, you should do that on the client. Why are you putting a string value inside the button?

0

String value was an archaic way for me to tell the server that a button had been pressed, but I don't think it works.

0

You can do it that way, but I don't think it's the best way. If you want, we can talk about it on discord? Lucy#4854