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

How can I turn this script into remote events?

local spawnloc = script.Parent.Name

script.Parent.CurrentOwner.Changed:Connect(function()

    if script.Parent.CurrentOwner.Value == BrickColor.new("Bright blue") then
        game.StarterGui.SpawnGui.Frame.Flag1.BackgroundColor3 = Color3.new(85/255, 170/255, 255/255)
        for i,v in pairs(game.Players:GetChildren()) do
            v.PlayerGui:FindFirstChild("SpawnGui").Frame:FindFirstChild(spawnloc).BackgroundColor3 = Color3.new(85/255, 170/255, 255/255)
        end

    elseif script.Parent.CurrentOwner.Value == BrickColor.new("Bright red") then
        game.StarterGui.SpawnGui.Frame.Flag1.BackgroundColor3 = Color3.new(255/255, 80/255, 80/255)
        for i,v in pairs(game.Players:GetChildren()) do
            v.PlayerGui:FindFirstChild("SpawnGui").Frame:FindFirstChild(spawnloc).BackgroundColor3 = Color3.new(255/255, 80/255, 80/255)
        end

    elseif script.Parent.CurrentOwner.Value == BrickColor.new("Fossil") then 
        game.StarterGui.SpawnGui.Frame.Flag1.BackgroundColor3 = Color3.new(207/255, 207/255, 207/255)
        for i,v in pairs(game.Players:GetChildren()) do
            v.PlayerGui:FindFirstChild("SpawnGui").Frame:FindFirstChild(spawnloc).BackgroundColor3 = Color3.new(207/255, 207/255, 207/255)
        end
    end

end)

This script doesn't work in a server script, it doesn't change the player's GUI for some reason, so how would I turn this into a remote event script to work?

4 comments

0

What are you trying to do?

0

I'm trying to change the Player's GUI depending on what script.Parent.CurrentOwner.Value is equal to. If it's == Bright blue then change Player's GUI to a Blue colour, if Red then Red etc.

0

What is script.Parent?

0

script.Parent is a model

1 answer

✓ Accepted answer
-- In a Server Script
local RemoteEvent = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
local CurrentOwner = -- whatever it is

CurrentOwner.Changed:Connect(function(NewValue)
    RemoteEvent:FireAllClients(NewValue) -- fires the remote event to everyone when it changes
)

-- In a Local Script in the GUI
local GUI = script.Parent
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

local function OnCurrentOwnerChange(NewValue)
    GUI.Frame.Flag1.BackgroundColor3 = NewValue.Color -- you can get the Color3 from a BrickColor by referring to its .Color
        for i,v in pairs(game.Players:GetChildren()) do
        GUI.Frame:FindFirstChild(spawnloc).BackgroundColor3 = NewValue.Color
        end
end

RemoteEvent.OnClientEvent:Connect(OnCurrentOwnerChange)

Note that I don't recommend actually making new RemoteEvents in Scripts themselves - a better option would be to make one in Studio with the appropriate name (such as CurrentOwnerChanged) then refer to that in the scripts instead.

This is not a perfect solution but I hope you get the idea.

1 comment

1

Works as expected, thanks a lot!

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