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

How can I turn this script into remote events?

Asked by 5 years ago
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?

0
What are you trying to do? NotInventedHere 158 — 5y
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. excellentAnarchy 50 — 5y
0
What is script.Parent? NotInventedHere 158 — 5y
0
script.Parent is a model excellentAnarchy 50 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
-- 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
Works as expected, thanks a lot! excellentAnarchy 50 — 5y
Ad

Answer this question