So, I tried to make a little chat-thing script. Once you look at the script you may understand. (There is an event in serverstorage.)
Event - Firer script. (LocalScript)
game.Players.PlayerAdded:Connect(function() game.ServerStorage.ChatEvents:FireServer("Ah, I have a headache... I can't see...") end)
Detector script in the textlabel . (Normal script)
game.ServerStorage.ChatEvents.OnServerEvent:Connect(function(sentence) local oof = tostring(sentence) -- I do this for safety script.Parent:TweenPosition(UDim2.new(0.25, 0, 0.85, 0), "In", "Linear", 0.2) for i = 1, #oof do script.Parent.Text = string.sub(oof, 1, i) end script.Parent:TweenPosition(UDim2.new(0.25, 0, 1.2, 0), "Out", "Linear", 0.2) script.Parent.Text = " " end)
edit like cows pointed out you need to move your remote to somewhere the client can use it such as the replicated storage. localscripts can't see the server storage
You are trying to use the player added event in a local script. Localscripts run when the player joins the game, or when the players character loads in depending on where you put them
This means when the player joins the game, the player added event will be made, but it will not recognize the player since the player already loaded into the game before the event was created.
Instead, you can put only this line of code in the local script and it'll run. (Also pls let me know where this script is located its important)
game.ServerStorage.ChatEvents:FireServer("Ah, I have a headache... I can't see...")
For your normal script, code should be the same, but instead of only having sentence in the parameter, we need to pass in the player and sentence:
game.ServerStorage.ChatEvents.OnServerEvent:Connect(function(player, sentence) local oof = tostring(sentence) -- I do this for safety script.Parent:TweenPosition(UDim2.new(0.25, 0, 0.85, 0), "In", "Linear", 0.2) for i = 1, #oof do script.Parent.Text = string.sub(oof, 1, i) end script.Parent:TweenPosition(UDim2.new(0.25, 0, 1.2, 0), "Out", "Linear", 0.2) script.Parent.Text = " " end)
It seems like you're tweening some sort of gui whenever a player joins the game. Is this a billboard or surface gui? Is it the players screen gui?
There are several issues here. The first issue is that your RemoteEvent is stored inside of ServerStorage
. It's called ServerStorage because only the Server can access it. That means when you try to fire the event from a LocalScript, the LocalScript can't actually access the remote to do so. Putting the RemoteEvent in ReplicatedStorage instead would work, as children of ReplicatedStorage do replicate to the client.
The next issue is your choice of script levels. When dealing with GUIs, it is always best to use a LocalScript because the GUI is only visible to the client anyway. Additionally, what you have in a LocalScript right now should be in a regular script because there's nothing that can't be done on the server. I'll write out what the script should look like, but it's important you know why these changes are being made so that you don't make the same mistakes in the future.
--Server script, located ideally in ServerScriptService game.Players.PlayerAdded:Connect(function(player) game.ReplicatedStorage.ChatEvents:FireClient(player, "Ah, I have a headache... I can't see...") end)
--Local script, located in the gui game.ReplicatedStorage.ChatEvents.OnClientEvent:Connect(function(sentence) --The rest of your code here end)
Let me know if you have any questions!
EDIT: This is assuming the Gui you are tweening is a ScreenGui and not a SurfaceGui or BillboardGui, in which case you should use a server script as you were doing before.