Trying to send information from a server side script to a local script

Trying to send information from the server script to the local script

Server Side Script

local SystemFolder = workspace:WaitForChild("PhoneSystem")
local PhoneGUI = game.ServerStorage.PhoneSystem.PhoneGUI

local ReplicatedStorage = game.ReplicatedStorage

for _, item in SystemFolder:GetChildren() do
	if item:IsA("Model") then
		
		local RoomNumber = item.Configuration.Room_Number.Value
		local RoomLocation = item.Configuration.Room_Location.Value

		-- Sets the Room Number/ Location to the phone screen
		item.Screen.SurfaceGui.OwnNumber.Text = "Room: ( "..RoomNumber.." )"
		item.Screen.SurfaceGui.Location.Text = "Location: "..RoomLocation

		-- Sees if the click detector has been pressed, if so it will clone the UI to the players GUI
		item.HitBox.ClickDetector.MouseClick:Connect(function(player)
			print("Click detector pressed on phone: "..item.Configuration.Room_Number.Value)
			local OpenUI_Event = ReplicatedStorage.PhoneSystem.OpenUI
			OpenUI_Event:FireAllClients(player, RoomNumber)
		end)
	end
end

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local OpenUI = ReplicatedStorage.PhoneSystem.OpenUI

OpenUI.OnClientEvent:Connect(function(player, roomNumber)
    print("Received phone number:", roomNumber)
end)

image

The local script needs to be somewhere that the client can access, like StarterPlayerScripts/StarterCharacterScripts, or StarterGui.

1 Like

Like @Haystees said, it needs to be somewhere the client can access.

I just want to add that a LocalScript is kind of picky about where it can run, as well as access places. It can only run in these places:

  • ReplicatedFirst
  • StarterPack
  • StarterPlayerScripts
  • StarterCharacterScripts
  • StarterGui
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.