How do I fire client on local script?


-- local script
local remote = game:GetService("ReplicatedStorage").RemoteFunction

sp.Button.MouseButton1Click:Connect(function () -- Start Progress
		print("clicked")

		if input == false then
			input = true
			tweencsspback(.1)
			
			remote:InvokeServer() -- problem here
			
			tweencompletedwait (tweencreverse, tweensreverse, tweenspreverse)

			input = false
		end

end)
-- script
local remote = game:GetService("ReplicatedStorage").RemoteFunction
local tps = game:GetService("TeleportService")
local TELEPORT_ID = 16340838478
local USER_ID = game.Players:GetPlayers()
local RESERVE_ID = tps:ReserveServer(TELEPORT_ID)

local function teleport ()
	print("teleporting")
	tps:TeleportToPrivateServer(TELEPORT_ID, RESERVE_ID, USER_ID)
end

remote.OnServerInvoke = teleport

So what I was going to do is when player click the button, it will automatically teleport to another server. From testing the game with 2 players. It suddenly teleport both of them. I tried doing “OnClientEvent” but it doesn’t show on the serverscript. I tried “OnInvokeServer” and it still didn’t work. I’m not that advance on scripting but i want to know if it can do “OnClientEvent” on local script and fires them. Please let me know.

1 Like

The remote function tells you which player activated it so you would use that information:

local function teleport (Player)
	print("teleporting")
	tps:TeleportToPrivateServer(TELEPORT_ID, RESERVE_ID, {Player})
end

3 Likes

Alongside @ZombieCrunchUK’s response;

I noticed the issue immediately; if you look at the USER_ID variable… you’re grabbing all the players, instead of the player that hit the button. Do what Sunny sent, and it should work perfectly.

3 Likes

I got it. Thank you so much for the information!

2 Likes

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