Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Text not changing with value?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

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
0
Is the variable 'value' a reference to a NumberValue named Value? BlackJPI 2658 — 8y
0
Yep yoshi8080 445 — 8y
0
I don't know Im kinda new to scripting but don't you have to have a space between else and if? duckyo01 120 — 8y
0
There is no space between else and if, it won't work like that. yoshi8080 445 — 8y

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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
0
This helps, thanks! Also the value does change... yoshi8080 445 — 8y
Ad

Answer this question