Why I cant use set local with RemoteEvents

I trying this:

--Script:
local Device = game:GetService("ReplicatedStorage").RemoteEvent:FireClient(player, what)
wait()
print(Device) -- prints only nil

--LocalScript:
game:GetService("ReplicatedStorage").RemoteEvent.OnClientEvent:Connect(function(what)
	if what == "1" then
		return "Character"
	elseif what == "2" then
		return "Player"
	end
	return "HAYHAY"
end)

just focus on codes.

The code on the variable is firing, not really declaring. You should try to check if the remote event actually exists in place first on client.

You can either use two or the same remote event where the client fires it and allowing the server to use OnServerEvent as an option, or simply the below.

if you want to return something to the server from a specific client, you have to use RemoteFunctions

More info

Never use InvokeClient, since exploiters can make the entire server hang.

2 Likes

then what should i do?

and why do we use it in roblox studio if there is no security at all?

You can use a yielding time limit. If the timer runs out, you can just use return nil. This will prevent exploiters from blocking out the server forever.