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

Why isn't the frame becoming visible with FE?

Hi! I want to enable a frame when a player says ":m" in the chat. I want to do this with FE. Anyone has an idea why it doesn't work?

Server Script:

local RS = game:GetService("ReplicatedStorage")
local Player = game.Players.LocalPlayer
local MessageEVENT = Instance.new("RemoteEvent", RS)
MessageEVENT.Name = "MessageEvent"
local function message(player)
    Player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Message").Visible = true
    print("MessageBox!")
end

MessageEVENT.OnServerEvent:Connect(message)

Local Script located in StarterCharacterScripts:

local Player = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
local messageEvent = replicatedstorage:WaitForChild("MessageEvent")
local function sendMessage(plr)
    plr.Chatted:Connect(function(message)
	    if message == ":m" then
		    messageEvent:FireServer()
	    end
    end)
end
game.Players.PlayerAdded:Connect(sendMessage)

1 comment

0

Two things: things in the PlayerGui are cloned into it localled, and a PlayerAdded event doesn't fire for the localplayer in a local script anywhere on the client

1 answer

✓ Accepted answer

The Chatted Event can be run on the Server, no local script or remote is required. https://developer.roblox.com/api-reference/event/Player/Chatted

Players.PlayerAdded:Connect(function(player)
    --run when a player joins.
    --check if player is allowed to run this command
    --before applying the Chatted event.
    
    player.Chatted:Connect(function(msg)
	    if (msg == ':m') then
		    --make frame visible
	    end
    end)
end)

However, I want you to understand the difference between the client and the server. Everyone that joins the game has their own client. Each client has their own set of things like LocalPlayer, Character, Camera, PlayerGui, etc. The server is, however, NOT a player. If you say Players.LocalPlayer on a server script, it'll end up being nil. The server is its own thing. If you want to replicate things to other clients, the server has to change it. With this, the server needs information from the client such as what player fired the remote. With that information, we can choose the right client and change what ever (in this case we would choose the player who said :m and make the GUI visible). The first parameter of the OnServerEvent sends the PlayerObject who fired the RemoteEvent. https://developer.roblox.com/api-reference/event/RemoteEvent/OnServerEvent

Good luck learning FE!

1 comment

0

Thank you so much!

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