Hello,
This script is supposed to run for all players in the game, but it only seems to run for the latest person that joined? It's strange, and I'm starting to feel like I may be on the wrong path? The script is supposed to affect everyone's UI. How would you go about fixing my script? Or is there a better approach?
I'm quite new to scripting, so all help and explanations are very much appreciated.
This is a server script in ServerScriptService. When there is only one player in the game, it works fine. Here is my current script:
--// Variables local RepStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local TextGui = script.NPCtext:Clone() local ServerText = script.ServerText:Clone() local PlayerText = script.PlayerText:Clone() local TextSound = script.TextSound local Text = "" --// Game Set-up Players.PlayerAdded:Connect(function(player) TextGui.Parent = player.PlayerGui ServerText.Parent = player.PlayerGui PlayerText.Parent = player.PlayerGui end) TextGui.Frame.Visible = false ServerText.Frame.Visible = false PlayerText.Frame.Visible = false --// Functions function ServerTextAni() local GuiType = ServerText local GuiText = Text GuiType.Frame.Visible = true for i = 1, #GuiText do GuiType.Frame.Text.Text = string.sub(GuiText, 1, i) TextSound:Play() wait(0.05) end wait(2) GuiType.Frame.Text.Text = "" GuiType.Frame.Visible = false end function TextAni() local GuiType = TextGui local GuiText = Text GuiType.Frame.Visible = true for i = 1, #GuiText do GuiType.Frame.Frame.Text.Text = string.sub(GuiText, 1, i) TextSound:Play() wait(0.05) end wait(2) GuiType.Frame.Frame.Text.Text = "" GuiType.Frame.Visible = false end function PlayerTextAni() local p = Players:GetPlayers() local selected_value = math.random(1,#p) local UserId = p[selected_value].Name local GuiType = PlayerText local GuiText = Text local player = p[selected_value] local thumbnailType = Enum.ThumbnailType.HeadShot local thumbnailSize = Enum.ThumbnailSize.Size420x420 local content, isReady = Players:GetUserThumbnailAsync(player.UserId, thumbnailType, thumbnailSize) GuiType.Frame.Player.Image = content GuiType.Frame.Visible = true for i = 1, #GuiText do GuiType.Frame.Frame.Text.Text = string.sub(GuiText, 1, i) TextSound:Play() wait(0.05) end wait(2) GuiType.Frame.Frame.Text.Text = "" GuiType.Frame.Visible = false end wait(1) Text = "Players are loading, please wait..." ServerTextAni() wait(5) Text = "Hello everyone, welcome to Clarenval Island!" TextAni() Text = "I'm Nathan Eyler, your tour guide for the week!" TextAni() Text = "Ugh, finally! It took such a long time!" PlayerTextAni() Text = "I'm exhausted!" PlayerTextAni() Text = "I can see that all of you are tired, don't worry; the cabins are not far away." TextAni() Text = "Come with me, I'll show you the way." TextAni() Text = "Follow your tour guide, Nathan. Be on the look-out for useful items!" ServerTextAni()
You will Have to make it run inside of a local script or it won't work correctly. If you need it to play the same time then you will have to make a Remote Event that fires at all the clients