✓ Accepted answer
The issue is that you're changing the Gui object in StarterGui. If this is a server script, your script is working like it's supposed to, however, you're not seeing the change because the contents of StarterGui are not cloned into the PlayerGui folder until the character reloads. To solve this issue, you can either...
Use a remote event
Use a local script
If you use a local script, it cannot be located in the workspace. You'll have to put it somewhere that is a direct descendant of the player, like StarterPlayerScripts, StarterGui, or StarterPack. This is an example with the local script:
local player = game:GetService("Players").LocalPlayer
local Button = workspace:WaitForChild("Button")
Button.Touched:Connect(function(part)
if part.Parent == player.Character then
player.PlayerGui.ScreenGui.TextLabel.Text = "STAGE: 2"
end
end)
Let's try this the other way as well:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Button = workspace:WaitForChild("Button")
local Remote = Instance.new("RemoteEvent")
Remote.Parent = ReplicatedStorage
Button.Touched:Connect(function(part)
local player = Players:GetPlayerFromCharacter(part.Parent)
if player then
Remote:FireClient(player,"")
end
end)
local player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("RemoteEvent")
Remote.OnClientEvent:Connect(function(args)
player.PlayerGui.ScreenGui.TextLabel.Text = "STAGE: 2"
end)
##Resources:
Local Script
##Accept and upvote if this helps!
3 comments
You can either: (1) Have a localscript deal with the Touched event of the part and change the TextLabel color via PlayerGui, although you wouldn't be able to put it in workspace (you wouldn't be able to use script.Parent) or (2) Fire a remove event to the player which a localscript then changes the TextLabel color in the player's PlayerGui
Would I have to put the LocalScript in StarterPlayerScripts?
Localscripts can run in a lot of places, see the bottom link of gioni01's answer for that. He turned what I said into an answer so that should help you