Hello,
In an obby I am making, whenever a player gets to a new stage, or touches the spawn point of the next stage, a checkpoint is set and the GUI text for a TextLabel is supposed to be changed to the stage that they are on.
I tried to use this:
script.Parent.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then game.StarterGui.ScreenGui.TextLabel.Text = "STAGE: 2" end end)
But it only changed when the player died. Any help? I am a beginner at scripting and may not understand the answer.
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 script located in StarterPlayerScripts 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)
--Server script in ServerScriptService 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,"") --you can send any data in the second argument end end)
--Local script in StarterPlayerScripts local player = game:GetService("Players").LocalPlayer local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = ReplicatedStorage:WaitForChild("RemoteEvent") --wait for remote Remote.OnClientEvent:Connect(function(args) --the data you sent player.PlayerGui.ScreenGui.TextLabel.Text = "STAGE: 2" end)