Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Text not changing with value?

I wanted to make a door that opens when the value reaches 0. Also the text that tells when the door is going to open and the status doesn't change! Help? local value = script.Parent.Value is a NumberValue

local value = script.Parent.Value
door = script.Parent.Door
local text = script.Parent.Parent.Model.Frame.SurfaceGui.Number.Text
local statest = script.Parent.Parent.Model.Frame.SurfaceGui.StatTitle.Text
while wait(1) do
value.Value = value.Value -1
text = "Time:"..value.Value

if value.Value >= 1 then
door.Transparency = .5
door.CanCollide = false
elseif value.Value <= 0 then
statest = "Status: Open"
value.Value = 10
text = "Time:"..value.Value
elseif value.Value <= 0 then
door.Transparency = 0
door.CanCollide = true
text = "Time:"..value.Value
statest = "Status: Close"
end
end

4 comments

0

Is the variable 'value' a reference to a NumberValue named Value?

0

Yep

0

I don't know Im kinda new to scripting but don't you have to have a space between else and if?

0

There is no space between else and if, it won't work like that.

1 answer

✓ Accepted answer

I'm not sure why the value isn't changing, but there are a couple other issues in this script.

The text isn't changing because you set the variables equal to the strings of text that the each GUI holds instead of making a reference to the GUI and setting the property after words.

local text = script.Parent.Parent.Model.Frame.SurfaceGui.Number
local statest = script.Parent.Parent.Model.Frame.SurfaceGui.StatTitle

text.Text = "Time: " .. value.Value
statest = "Status: Closed"

The second problem is that have two elseif statements that have the exact same parameters. This means that the second on will never function. Instead I used a variable to determine the state of the door.

local open = false

if value.Value == 0 then
	open = not open -- Switch true to false and vice-versa
	if open then
		door.Transparency = 0.5
		door.CanCollide = false
	else
		door.Transparency = 0
		door.CanCollide = true
	end
	value.Value = 10
end

Full Script

local value = script.Parent.Value
local door = script.Parent.Door
local text = script.Parent.Parent.Model.Frame.SurfaceGui.Number
local statest = script.Parent.Parent.Model.Frame.SurfaceGui.StatTitle
local open = false

while wait(1) do
	value.Value = value.Value - 1
	text.Text = "Time: "..value.Value

	if value.Value == 0 then
		open = not open -- Switch true to false and vice-versa
		if open then
			door.Transparency = 0.5
			door.CanCollide = false
		else
			door.Transparency = 0
			door.CanCollide = true
		end
		value.Value = 10
	end
end

1 comment

0

This helps, thanks! Also the value does change...

This discussion is preserved as it was. New answers, comments, and votes are closed.