Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Remote event is client sided instead of server sided?

So I have a problem with my script. When I fire this remote event it only shows for the client. Heres the scripts.

Local Script:

local rp = game.ReplicatedStorage
local remote = rp.Claim
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	print("Claimed")
	script.Parent.Parent.FinishOrderFrame.Visible = true
	script.Parent.Parent.FinishOrderFrame.Parent = player.PlayerGui.FinishOrder
	remote:FireServer(script.Parent.Parent.Claimed, player, script.Parent, script.Parent.Parent)
end)

Server Script:

local rp = game.ReplicatedStorage
local remote = rp.Claim

remote.OnServerEvent:Connect(function(player, v, playername, z, x)
	v.Text = "Claimed by: "..playername.Name
	z.Visible = false
	wait(5)
	x:Destroy()
end)

Can anybody help me why the remote event only shows for the person who clicks on the GUI button?

1 answer

✓ Accepted answer

The objects you sent from the client (v,z,x) are only stored in the playerGui of the player. This is why it will not replicate to other clients. Instead you can use game:GetPlayers() and itterate through it with a for loop. For each itteration, you can update the guis elements inside the player gui to whatever you want.

Also, never trust the client. When you fired the remote event you gave some text label objects. This is not a good idea because exploiters can do the same thing, but change the textlabel.text property to something offensive and other players will see it.

Instead, you can rename the remote to something specific like "PlayerFoundSomething" and just fire the remote event with no arguments. Now if the exploiter fires to the server, it is impossible for the exploiter to change the text because the exploiter nor anyone can change the name of a player object (which is the only parameter by default).

Example:

-- Client

local rp = game.ReplicatedStorage
local remote = rp.Claim
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    print("Claimed")
    script.Parent.Parent.FinishOrderFrame.Visible = true
    script.Parent.Parent.FinishOrderFrame.Parent = player.PlayerGui.FinishOrder
    remote:FireServer()
end)

-- Server

local rp = game.ReplicatedStorage
local remote = rp.Claim

remote.OnServerEvent:Connect(function(player)
	local players = game.Players:GetPlayers() -- All the clients in the game
	
	for _, player in pairs(players) do
		local playerGui = player.PlayerGui
		local textlabel = playerGui.Gui.textLabel
		texlabel.Text = "Claimed by: " .. player.Name

		wait(5)
		textlabel:Destroy()
		-- Customize this code inside of the for loop to your liking
	end
end)

I hope this helps :)

11 comments

0

Thank you! I will try it later. I hope this will work!

0

No problem!

0

Just remember that you can change a gui on a client during the game, by accessing player.PlayerGui which will contain anything that was in the StarterGui

0

The server cannot access GUIs. That's on the Client. You can loop through all the players in the server just like what IceyTazeForLife is showing you here, but you cannot fire a RemoteEvent and expect the server to be able to access something that is on the Client. You can do this all in your one LocalScript or use a BindableEvent which allows server-server and client-client communication.

0

Here's a link if you want to learn about BindableEvents: https://developer.roblox.com/en-us/api-reference/class/BindableEvent#event-tuple-arguments-. However, RemoteEvents allow server-client communication and vice versa.

0

That is true because the client makes changes that the server does not know about so it's guaranteed to cause unknown behavior. But anyways in that script it didn't make much of a difference. Thanks for the feedback! I will be sure to use that from now on. 

0

But also you can have some values in replicatedStorage and when the server updates those values, using :GetPropertyChangedSignal on the client you can see what the new value is and update the gui from a local script.

0

It looks like I've ran into a problem. Since the GUI will be cloned multiple times, the script will not know which GUI that needs the textlabel to be changed. Do you have any solutions to this?

0

Instead of accessing the player gui from the server, use a remote event and on the server, when someone claim's whatever, fire the remote to all the clients by doing event:FireAllClients(player.Name) and pick it up on the client to display the name of who claimed whatever.

0

Thank you! This worked!

0

No problem! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.