Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Remote event is client sided instead of server sided?

Asked by
Neatwyy 123
4 years ago

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

Log in to vote
0
Answered by 4 years ago

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 :)

0
Thank you! I will try it later. I hope this will work! Neatwyy 123 — 4y
0
No problem! IceyTazeForLife 253 — 4y
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 IceyTazeForLife 253 — 4y
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. AntiWorldliness 868 — 4y
View all comments (7 more)
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. AntiWorldliness 868 — 4y
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.  IceyTazeForLife 253 — 4y
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. IceyTazeForLife 253 — 4y
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? Neatwyy 123 — 4y
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. IceyTazeForLife 253 — 4y
0
Thank you! This worked! Neatwyy 123 — 4y
0
No problem! :) IceyTazeForLife 253 — 4y
Ad

Answer this question