How would I make gui text change from a script in the workspace?

I am working on a game and I want a majority of the functionality to come from a script in a chair I am doing, but how would I change text in a GUI in screenGui from the script in the seat? It is a basic one player game, so hopefully that makes it a bit easier.

this is the script I am talking about:
image

Do I use remoteEvents? I am just a bit unsure on what path I should take that would be the easiest.

Thanks,
Harry.

1 Like

While you don’t necessarily need to change it on the client directly, you should aim to keep anything that deals with GUIs on the client side. And yes, you will need a remote event that fires the client to change the text. Oh, and you want to make changes to the PlayerGui, if you didn’t already know

How would I go about doing this? Could you give me a basic outline or script?

This would go in your script that is inside your seat.

RemoteEvent:FireClient(player) --You will need something that defines the player, so maybe a GetPlayerFromCharacter() type of situation

This could go inside starter player script, or inside startergui, but it must be a local script

local player = game.Players.LocalPlayer
     RemoteEvent.OnClientEvent:Connect(function()
     player.PlayerGui.ScreenGui.TextLabel.Text = "Changed text" --Put whatever you want it to change to
end)

You will need to include the paths for where your remote event is stored, and not just say “RemoteEvent” like I did for the example

5 Likes

I don’t think you need a RemoteEvent in order to change text serversided.

how would you do it?

3 0 c h a r a c h t e r s u g h

Wouldn’t it be something like:

local textLabel = script.Parent.TextLabel
while true do
wait(1)
textLabel.Text = "Hey"
wait(1)
textLabel.Text = "How are you?"
end

You could do it that way, like I said previously. But it’s better to have GUIs controlled by local scripts, since they are solely for the client to see. That doesn’t mean you can’t change it like you said, but it’s just a preference and suggestion that I’m giving out

2 Likes

Try using a StringValue or the value type you need in somewhere like ReplicatedStorage, then with a server script try changing the value, something like this:

local Status = game.ReplicatedStorage:WaitForChild('StringValue') -- There would be a StringValue on ReplicatedStorage

for i = 30,0,-1 do
Status.Value = 'Current time is: '.. i
end

Now that you are changing the value in the server, through a local script you will change the TextLabel text, for example:

local Status = game.ReplicatedStorage:WaitForChild('StringValue')

Status:GetPropertyChangedSignal('Value'):Connect(function() -- When Value is changed, this fires.
script.Parent.Text = Status.Value -- We change the value through the server, then we get the text from the value and finally we set the property to the value.
end)

Either if you want to change it for only one player or as you wanted then:

local seat = workspace.Seat or script.Parent

local function onTouch(hit)
local playerName = hit.Parent.Name
if game.Players:FindFirstChild(playerName) then
local Player = game.Players:GetPlayerByCharacter(hit.Parent)
Player.PlayerGui.ScreenGui.TextLabel.Text = '' -- Modify to your gui name, text, etc.
end
seat.Touched:Connect(onTouch) -- I made this really fast, however. This won't work really unless there is a check if the player is seated.

If you think that I’m wrong or have any feedback please reply to me.

4 Likes

You dont have to use a RemoteEvent, you can get the player more easy with a touch function for example :

local Seat = script.Parent
local function touched(getplayer)
local player = game.Players:GetPlayerByCharacter(getplayer)--That get the player that touched the part or seat
player.PlayerGui.INSERTYOURSCREENGUINAMEHERE.TextLabel.Text = ""--Text you want to change
end
Seat.Touched:Connect(touched)

I hope this worked!

1 Like

Like I said in two previous replies, this way is possible without a remote event. I just find it better to change all GUIs on the client side, since it will always remain client sided. In this case, yes this works. I’ve experienced in other cases with going back and forth between controlling GUIs on the server and client can mess things up.

1 Like

Sorry, I am pretty new to scripting, and was just wondering, why doesn’t this work?
local function onPlayerAdded(player)

wait(3)

script.Parent.Text = “I see…”

end

The pathing is right, could someone tell me what’s wrong?

I am not the best at scripting but I might be able to help for this one can you show your path and full script for the text changing? you might not be running the function at all.

Sure. I changed it to this, but it still doesn’t work.
StarterGui
Startgamegui
Frame
TextLabel Text

local function onPlayerAdded(player)

game.StarterGui.Startgamegui.Frame.TextLabel.Text= “Well, we don’t have much time. I am just an AI controlling a GUI.”

end

I think you are just not running it as I said onPlayerAdded is the name of the function I think you are getting confused with

game.Players.PlayerAdded:Connect(function(Plr)

Lets say you have your GUI Where you said.

-- Services
local Players = game:GetService("Players")

-- Local Player
local Player = Players.LocalPlayer

-- Path to the gui
local GuiPath = Player.PlayerGui:WaitForChild("Startgamegui"):WaitForChild("Frame")

-- Function to be ran
local function onPlayerAdded()
GuiPath.TextLabel.Text = "Well, we don't have much time. I am just an AI controlling a GUI."
end

-- Function is ran on player added
game.Players.PlayerAdded:Connect(function(Player)
onPlayerAdded()
end

I am not 100% sure it will work but you can give it a try :slight_smile:

Will give it a shot! Ill tell you if it works!

Its still not changing the text for some reason. I dont’ know if its a pathing issue? I did put a ) after end.

let’s go in private messages to not flood this thread I will try to help you because I know I can make it work as I have done it before lol.

New here! How do you do that? lol