Help this text changing script wont work

Hi, im having a problem that this script wont work
it is used so when the timer reaches a certain number a screengui will get enabled
(screengui is disabled on propeties)

thanks you in advance if you helped me :slight_smile:

local t = script.Parent.Text -- textlabel
local s = script.Parent.Parent -- screen gui

if s.Enabled == true then
	t ="hey"
	wait(2)
	t = "do you want a secret"
	wait(2)
	t = "look behind you"
	wait(2)
	t = "a small door right?"
end

Your problem is the script will run as soon as it’s loaded so if s.Enabled==false then nothing will happen and it doesn’t check again. You can make use of ** GetPropertyChangedSignal** for this. It can trigger a function that will run when the value has changed:

local t = script.Parent.Text -- textlabel
local s = script.Parent.Parent -- screen gui

local function MyFunction()
	if s.Enabled == true then
		t ="hey"
		wait(2)
		t = "do you want a secret"
		wait(2)
		t = "look behind you"
		wait(2)
		t = "a small door right?"
	end
end

s:GetPropertyChangedSignal("Enabled"):Connect(MyFunction)

you should really use task.wait()

Why?
If the timer is being run on the server and the player joins a little late then task.wait wouldn’t be synced with the timer unless you write more code to get current time on the timer etc - which is more effort than needed.

EDIT: Never mind :rofl: I think you meant use task.wait() instead of wait() in the function lol Yes I agree!, I just copied/pasted his original code without editing.

Hi, thanks for the reply but it still doesnt work

My mistake!
Change to s:GetPropertyChangedSignal

It still doesnt work maybe something missing?

I just tested the script in Studio and it works as expected. Check your code that changes the Enabled value of the giu to make sure it is being enabled.

Ok, thanks i will go check the code

i cant seem to find the error it still wont work
here is the script for the timer maybe its the problem?

local ScreenGui = script.Parent
local value = 0
local maxValue = 5
local humanoidSeated

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Seated:Connect(function(active, currentSeatPart)
	print(active)
	if active then
		humanoidSeated = true
		while value ~= maxValue + 1 do
			ScreenGui.Parent.Timer.TextLabel.Text = (value)
			task.wait(1)
			if not humanoidSeated then break end
			value += 1
		end
		ScreenGui.Enabled = true
	else
		humanoidSeated = false
		value = 0
		ScreenGui.Enabled = false
	end
end)

That code seems ok.
One thing I noticed in your original script was this line:
local t = script.Parent.Text – textlabel
is Text the NAME of the textlabel?
if so then you will need to change the values in your function to
t.Text=“hey” … change the other t= to t.Text= too

haha i feel stupid , thanks for telling me
all i need to do is change the t
i forgot the local is used for naming only

local t = script.Parent
t.text = "thanks"

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.