How to get info from the client side to transfer to server side?

how to get info from the client side to transfer to server side?
I have ui button that the player clicks, but the text of the button always changes when player clicks which is using a local script. How can I transfer the text change to the server side?

Script in serverscriptservice

game.Players.PlayerAdded:Connect(function(plr) 
	task.wait(8)
	while true do
		task.wait(2)
	local b = plr.PlayerGui.nope.TextButton.Text
		print(b)
		end
end)

I am a ware that I can just use normal scripts but I want to know if there is any other way.

RemoteEvent
RemoteFunction

1 Like

I tried using the remote events and it is still printing the button’s default name that is on server side.

local script in ui button:

script.Parent.MouseButton1Click:Connect(function ()
	local y = script.Parent.Text 
	script.Parent.Text = math.random(1, 100)
	game.ReplicatedStorage.RemoteEvent:FireServer(y)
end)

script in serverscriptservice:

game.Players.PlayerAdded:Connect(function(plr) 
	task.wait(8)
	while true do
		task.wait(2)
		game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(y)
		print(y.PlayerGui.nope.TextButton.Text)
	local b = plr.PlayerGui.nope.TextButton.Text
		print(b)
		end)	
		end
end)

The first argument for the OnServerEvent and OnServerInvoke events is the player firing/invoking the remote. So what you should do is:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, y)
	--your code
end)

Also the remote must be connected once, not multiple times:

local texts = {}

game.Players.PlayerAdded:Connect(function(plr) 
	task.wait(8)
	while task.wait(2) do
		print(plr, texts[plr])
	end
end)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, y)
	texts[plr] = y
end)
1 Like

Thank you

This text will be blurred

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