Server Side Scripts & GUI

Hi. I’m trying to get my head around RemoteEvents and how they can be used to trigger a GUI change for all clients, however, as expected, I ran into an issue.

It’s worth noting that my scripting knowledge isn’t at all huge, so this is quite frustrating. Here’s a LocalScript under StarterPlayerScripts

local remoteEvent = ReplicatedStorage:WaitForChild("ActivateCrystals")
local plr = game.Players.LocalPlayer
local PPS = game:GetService('ProximityPromptService')
local ProximityPrompt = game.Workspace.proxPart1.ProximityPrompt
local proxPart = game.Workspace.proxPart1

local function onPromptTriggered(ProximityPrompt, plr)
	proxPart:Destroy()
	remoteEvent:FireServer()
end

PPS.PromptTriggered:Connect(onPromptTriggered)

I then placed a Script inside ServerScriptService, shown below

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("ActivateCrystals")
local plr = game.Players.LocalPlayer

local Crystal = game.Workspace.Crystal
local Crystal2 = game.Workspace.Crystal2
local startPos = Crystal.Position
local startPos2 = Crystal2.Position

local function moveCrystals()
	task.spawn(function()
		while (true) do
			wait()
			Crystal.Position = startPos + Vector3.new(0,math.sin(tick(), Enum.EasingDirection.In), 0)
			Crystal2.Position = startPos2 + Vector3.new(0,math.sin(tick(), Enum.EasingDirection.In), 0)
		end
		
		remoteEvent:FireAllClients()
		
		plr.PlayerGui.CrystalCounting.CrystalCountPrompt.CrystalCounter.Text = '1/4'

		local prompt = plr.PlayerGui.CrystalMessagePrompts.CrystalPrompts.CrystalPrompt

		plr.PlayerGui.CrystalMessagePrompts.CrystalPrompts.CrystalPrompt.Visible = true

		prompt.AnchorPoint = Vector2.new(0, 0)
		prompt.Position = UDim2.new(0.343, 0, 1, 0)
		prompt:TweenPosition(UDim2.new(0.343, 0, 0.642, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quint) 

		plr.PlayerGui.CrystalMessagePrompts.CrystalPrompts.CrystalPrompt.Text = plr.Name .. ' activated a crystal!'

		wait(3)
		prompt:TweenPosition(UDim2.new(0.343, 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quint)

		wait(5)
		plr.PlayerGui.CrystalMessagePrompts.CrystalPrompts.CrystalPrompt.Visible = false
	end)
end

remoteEvent.OnServerEvent:Connect(moveCrystals)

The actual crystals do what they’re supposed to do - which is to move. However, the actual GUI isn’t showing, or doing anything for that matter. The dev console isn’t showing any errors either, which is quite perplexing.

I’d be grateful for any help I can get. Thanks.

Ah I see the issue:

You are using the normal script to change the Gui which isn’t possible

Is there another way to achieve a GUI change then?

The only way to do this is by using a local script.

You can use the same event you used to send the server a signal to send a signal to the local script and do the stuff from there.

You can do something like this:

:FireServer() -> :FireAllClients()

Tried that already, got an error. You can only FireAllClients from a server script.

Oh, so communicating back to the client from the server?

1 Like

Wait, let me rephase this:

FireServer will fire to a serverscript, AND THEN the serverscript will FireAllClients

Already put that in the Server Side script. I’ll look into the issue elsewhere.