How to fire the effects of a LocalScript to the server

I’m trying to make a script that takes a Color3Value in a local client, and changes a block’s color in the server client.

This script has to be a LocalScript in order to work with the color picker I have in UI. This UI works locally and changes the Color3Value locally as well.

I’ve heard about using FireAllClients and FireServer() to deal with these sort of issues, but I don’t know how to implement this into the script. I’ve also tried in the past and it hasn’t worked.

Your help is appreciated. :heart:

2 Likes

You can’t use FireAllClients() on the client side, only on the server

Also what do you mean by “server client”? There’s only the server-side area

From what I’m thinking, you could use FireServer() to send whoever fired the event on the client, then use FireAllClients() on the server so that it’ll be replicated to every client individually??? Idk

2 Likes

Thank you. I edited the title of my post.

Okay much better

Yeah what you can do, is fire the event from the client side & pass on the feedback variable onto the server so everyone would be able to see the color change?

local Button = script.Parent
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
print("Test")

local function onButtonActivated()
    print("Bruh")
    local feedback = workspace.DISPLAY.ColorTransmit
    --This is only if you want to have the changes made locally, you can comment this if you want it server sided
    workspace.ROOFC1.Visual.Color = feedback.Value
    --Firing Event
    Event:FireServer(feedback.Value)
end

Button.MouseButton1Down:Connect(onButtonActivated)

And then on a random server script, preferably in ServerScriptService:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(Player, Color)
    print(Player)
    workspace.ROOFC1.Visual.Color = Color
end)

Usually whenever you call OnServerEvent, the first parameter would be the player that fired the event, afterwards we can call our tuple arguments (Or our Color value)

Doesn’t work. I don’t know what is causing a problem because there’s no outstanding errors in the script or in output when the scripts are run.

I think

I forgot

To connect the function FACEPALM

Unless if you did that yourself and saw my mistake

I did not connect the function, no.

Yeah I edited the post, try it again lol

I made the changes. Still doesn’t work.
Once again, no errors or anything.

Ok remind me that case-sensitive variables are dumb

Attempt #3, I edited it yet again: Print Edition

The script stops before it can print “Test”.

I did the labor of adding a print("test") after every line, and discovered that it stops working at this line:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Oh, did you even put a RemoteEvent object inside the ReplicatedStorage service? If you haven’t, please do so

Otherwise the script would just result back as an “infinite yield” warning

1 Like

Works like a charm! Thank you.

1 Like