Event replacing it's arg

All of a sudden my event are replacing the 2nd arg (argument) with the 1st

Client Gui Script:

for _,Button in pairs (Main.GuiManager.TestButtons:GetDescendants()) do
		if Button:IsA("TextButton") then
			Button.MouseButton1Click:Connect(function() -- Event per button
				if not Clicked and Button.Active == true then -- Button debounce
					Clicked = true
					print(player, Button)
					TPWC:InvokeServer(player,Button)
					RunService.Heartbeat:Wait()
					Clicked = false
				end
			end)
		end
	end

Server Script:

TPWC.OnServerInvoke = function(player, Button)
	print(player,Button)

Results: Screenshot 2021-03-31 152651

Anyone know why this is happening?

1 Like

You do not pass in the player yourself

TPWC:InvokeServer(player,Button)

Change this to this

TPWC:InvokeServer(Button)

It’s given automatically, the same as how FireServer works

1 Like

With that change I got nil printed

Screenshot 2021-03-31 153559

That’s odd, it should’ve worked, by any chance which script did you change?

Sorry for late reply, I changed the local script

for _,Button in pairs (tppanel.Main.GuiManager.TestButtons:GetDescendants()) do
		if Button:IsA("TextButton") then
			Button.MouseButton1Click:Connect(function() -- Event per button
				if not Clicked and Button.Active == true then -- Button debounce
					Clicked = true
					print(player, Button)
					TPWC:InvokeServer(Button) <- Removed "player," 
					RunService.Heartbeat:Wait()
					Clicked = false
				end
			end)
		end
	end

I think the server is unable to see the TextButton, try giving it something like the name of the button and see if it prints from the server?

Passing the name worked, however I need the instance of the button and not just the name. Maybe there’s a way to scan the gui from the server for mouse inputs instead of the client?

What are you trying to do exactly in your code?

Buttons are for a teleport panel in a simulator, need the instance so I can find the location to teleport a player to

Why are you using a RemoteFunction for that if you’re not wanting to retrieve something? Convert it to a RemoteEvent, although the Button may not still be detected. What’s in the code for the OnServerInvoke?

It’s for if the player is at the place they want to go to, it would invoke back to the client from the server to create some text telling them that they are there

Hmm, may I see what’s in the OnServerInvoke function?

ServerInvoke:

TPWC.OnServerInvoke = function(player,Button)
	print(player,Button)
	local ButtonName = tostring(Button.Parent.Parent.Name) -- Get World name
	for _,Maps in pairs (game.Workspace.Map:GetChildren()) do -- Get current maps
		if tostring(Maps) == ButtonName then -- TpPos == ButtonMap
			if tostring(Maps) == player.BPack.CurrentWorld.Value then -- Player is in world
				TPWC:InvokeClient(player,Button)
			else
				TP(player,Maps)
				TPWC:InvokeClient(player)
			end
		end	
	end
end

ClientInvoke:

TPWC.OnClientInvoke = function(Button)
	if Button then
		
	-- Save current colors --
	table.insert(Color,Button.BackgroundColor3)
	table.insert(Color,Button.Parent.BackgroundColor3)
	table.insert(Words,Button.Text)
								
	-- Set Error --
	Button.BackgroundColor3 = Color3.fromRGB(163,163,163)
	Button.Parent.BackgroundColor3 = Color3.fromRGB(79,79,79)
	Button.TextColor3 = Color3.fromRGB(0,0,0)
	Button.Text = "That's here!"
	wait(2)
				
	-- Revert --
	Button.BackgroundColor3 = Color[1]
	Button.Parent.BackgroundColor3 = Color[2]
	Button.TextColor3 = Color3.fromRGB(255,255,255)
	Button.Text = Words[1]
				
	-- Garbage Collection --
	table.clear(Color)
	table.clear(Words)
	else
		Exit() 
	end
end

Can’t you just pass in Button.Parent.Parent.Name instead of the button instance and just change the code around in the ServerInvoke?

TPWC:InvokeServer(Button.Parent.Parent.Name)
1 Like

Huh, didn’t think about it like that. Thanks! :smiley:

1 Like

Anytime! If oyu have anymore issues don’t be afirad ot make another post!

1 Like