Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My text GUI isn't changing for everyone in the server?

Asked by 5 years ago
Edited 5 years ago

Hello! Recently I have been making a camping like game and I've been using scripts to change the text on the text label. But for some reason, only a few or maybe even 1 user is seeing the change and the rest getting stuck on some text.

I'm not sure if I'm doing anything wrong with the code but the script is just a normal script, the code is below if you want to know it.

local NPC = game.Workspace.Josh
local Monster = game.Workspace.Monster
local Background = game.Workspace.BackgroundMusic
local NightMusic = game.Workspace.NightMusic
local TextGUI = game.StarterGui.ScreenGui.Frame.TextLabel.Text

NPC.Torso.Anchored = true
Background.Playing = true
Background.Looped = true
TextGUI = "Lets wait for everyone to get in!"
wait(40)
NPC.Torso.Anchored = false
TextGUI = "Lets get moving then! We will set camp in the forest."
game.Workspace.WallA1.CanCollide = false
game.Workspace.WallA2.CanCollide = false
game.Workspace.WallA3.CanCollide = false
NPC.Humanoid:MoveTo(game.Workspace.Point1.Position)
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(game.Workspace.Point1.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait()
NPC.Torso.Anchored = true
TextGUI = "We will set up camp here! Feel free to explore whilst I set up!"
wait(50)
TextGUI = "Night is approching..."
game.ServerStorage.Evening.Parent = game.Lighting
game.Lighting.Day.Parent = game.ServerStorage
wait(10)

All up to there is fine but then people get stuck with "Night is approaching..." and then nothing else, I think the whole script stops from there but I'm not sure as I've never had this issue but my BETA testers have.

The lines of code that follow the are.

TextGUI = "Night is here! Everyone get settled in your tents and tell some scary stories!"
game.StarterGui.BlacknessGUI.Frame.Visible = true
game.ServerStorage.Night.Parent = game.Lighting
game.Lighting.Evening.Parent = game.ServerStorage
game.Workspace.Camp.Campfire.Sphere1.Flame.Enabled = true
game.Workspace.Camp.Campfire.Sphere1.LightParticles.Enabled = true
game.Workspace.Camp.Campfire.Sphere1.Sparks.Enabled = true
game.Workspace.Camp.Campfire.Sphere2.Flame.Enabled = true
game.Workspace.Camp.Campfire.Sphere2.LightParticles.Enabled = true
game.Workspace.Camp.Campfire.Sphere2.Sparks.Enabled = true
game.Workspace.Camp.Campfire.Sphere3.Flame.Enabled = true
game.Workspace.Camp.Campfire.Sphere3.Sparks.Enabled = true
wait(3)
game.Workspace.WallB1.CanCollide = true
game.Workspace.WallB2.CanCollide = true
game.Workspace.WallB3.CanCollide = true
game.Workspace.WallB4.CanCollide = true
wait(1)
game.StarterGui.BlacknessGUI.Frame.Visible = false
Background.Playing = false
Background.Looped = false
NightMusic.Playing = true
NightMusic.Looped = true
wait(15)
TextGUI = "I'm just going to the bathroom! I'll be back soon!"
wait(1)
NPC.Torso.Anchored = false
NPC.Humanoid:MoveTo(game.Workspace.PointB2.Position)
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(game.Workspace.Point2.Position)
NPC.Humanoid.MoveToFinished:Wait()
game.Workspace.WallB3.CanCollide = false
NPC.Humanoid:MoveTo(game.Workspace.Point3.Position)
NPC.Humanoid.MoveToFinished:Wait()
game.Workspace.WallB3.CanCollide = true
NPC.Humanoid:MoveTo(game.Workspace.Point4.Position)
NPC.Humanoid.MoveToFinished:Wait()
game.Workspace.BathroomBlocker.CanCollide = false
NPC.Humanoid:MoveTo(game.Workspace.Point5.Position)
NPC.Humanoid.MoveToFinished:Wait()
script.Parent.Parent.ImageLabel.Visible = false
wait(2)
TextGUI = "Lets all get ready for bed! We should get into our tents."
wait(10)
game.Workspace.TentDoor1.Transparency = 0
game.Workspace.TentDoor2.Transparency = 0
game.Workspace.TentDoor1.CanCollide = true
game.Workspace.TentDoor2.CanCollide = true
wait(10)
game.Workspace.Screaming.Playing = true
wait(10)
game.Workspace.Stab.Playing = true
game.Workspace.DeadBody.CanCollide = true
game.Workspace.DeadBody.Transparency = 0
wait(15)
game.Lighting.Night.Parent = game.ServerStorage
game.ServerStorage.Day.Parent = game.Lighting
NightMusic.Playing = false
Background.Playing = true
game.Workspace.TentDoor1.Transparency = 1
game.Workspace.TentDoor2.Transparency = 1
game.Workspace.TentDoor1.CanCollide = false
game.Workspace.TentDoor2.CanCollide = false
wait(1)
TextGUI = "Oh my god! What happened!"
wait(5)
NPC.Humanoid:MoveTo(game.Workspace.Point4.Position)
NPC.Humanoid.MoveToFinished:Wait()
game.Workspace.BathroomBlocker.CanCollide = true
NPC.Humanoid:MoveTo(game.Workspace.Point3.Position)
NPC.Humanoid.MoveToFinished:Wait()
game.Workspace.WallB3.CanCollide = false
NPC.Humanoid:MoveTo(game.Workspace.Point2.Position)
NPC.Humanoid.MoveToFinished:Wait()
game.Workspace.WallB3.CanCollide = true
NPC.Humanoid:MoveTo(game.Workspace.PointB2.Position)
NPC.Humanoid.MoveToFinished:Wait()
NPC.Humanoid:MoveTo(game.Workspace.Point1.Position)
NPC.Humanoid.MoveToFinished:Wait()
script.Parent.Parent.ImageLabel.Visible = true
wait(1)
TextGUI = "I heard screaming last night so I stayed in the bathroom."
wait(4)
TextGUI = "What happened here?! Is that what the screaming was?!"
wait(999999999999999)

I'm not sure what I've done wrong after that but for some reason its glitches at the end and redoes the text from the Night if approaching bit, so I added the long wait onto the end as I haven't finished coding and won't until I can fix this bug.

The script is located in ServerScriptService but I've tried putting it in may place such as in the Text Label. I'm not sure if its an error I have made or just a bug. I've also noticed that the part that says

game.StarterGui.BlacknessGUI.Frame.Visible = true

and

game.StarterGui.BlacknessGUI.Frame.Visible = false

Doesn't work for some reason, I've done this before a while back and it worked fine but as soon as I try and recode it and make a new one, nothing works.

I am also aware that I have put something to do with script.Parent somewhere for an ImageLabel, this is because the script was in the text label before.

0
yeah, game.StarterGui doens't change for anybody.. ryan32t 306 — 5y

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

This can easily be accomplished by using a RemoteEvent.

RemoteEvents and RemoteFunctions enable the server to communicate with the clients. For changing the GUI, I would suggest setting an event for the server to detect, and when that event happens, fire the event/function to every client and change the text from the client.

Here is an example of doing so.

A sample server script:

local event = game:GetService("ReplicatedStorage"):WaitForChild("TextEvent")
local text = "Fired from the server"
local canFire = true
script.Parent.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) and canFire then
        canFire = false
        event:FireAllClients(text)
        wait(3)
        canFire = true
    end
end)

The local script in a TextLabel in the PlayerGui:

local event = game:GetService("ReplicatedStorage"):WaitForChild("TextEvent")
event.OnClientEvent:Connect(function(text)
    script.Parent.Text = text
end)

Here's how it works.

The server receives a touch from the script parented to the BasePart. When Touched fires, it checks for two things:

A) Has a player touched the part?

B) Is the debounce variable canFire set to true?

If both conditions evaluate to be true, the debounce variable is set to false, the event is fired to every client with text being the argument fired, and 3 seconds later the debounce variable is set back to true.

The client receives the event and assigns the argument passed by the server to the Text of the TextLabel the script is parented to. That's how it works.

One thing I should mention to you: Do not assign a property value to a variable. If you assign a value, such as Text, to a variable, and you change the value later, the value of the variable will change but the text will not. The value of the property is being changed indirectly. You should never do this because it will always end in a roadblock.

0
I've been trying to get better at RemoteEvents and this should help me! MustangHeart 67 — 5y
0
Ahhh, Its been a while but thank you! DiamondRules01 56 — 4y
Ad
Log in to vote
0
Answered by 5 years ago

You should use this:

for i,v in pairs(game.Players:GetPlayers()) do
    local TextGUI = v.PlayerGui.ScreenGui.Frame.TextLabel.Text 
    TextGUI = "your text here :)"
end
0
The server cannot access the descendants of the PlayerGui unless it cloned an object into it or created a new instance and parented it to the PlayerGui, in which case it can only see the object it put into the PlayerGui. This also doesn't work because you're indirectly changing the value. DeceptiveCaster 3761 — 5y

Answer this question