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

Timer wont run...IntValue wont trigger timer??? Help(GUI)

Asked by 4 years ago

i am developing a game and my script wont run in serverscript service(longscript) first script(in startergui inside a textbox)

01timer = script.Parent
02val = game.ReplicatedStorage.Timer
03intro = game.ReplicatedStorage.Intro
04t = game.ReplicatedStorage.T
05 
06while true do
07    if intro.Value == 1 then -- part that was referenced in script below
08        timer.Visible = true -- timer wont go visible
09        timer.Text = "0:"..val.Value
10    val.Value = val.Value - 1 -- timer wont go down a second
11    end
12    if timer.Text == "0:0" then -- this part works fine
13        local it = game:WaitForChild("ReplicatedStorage").It
14        it:FireServer()
15        timer.Visible = false
16        intro.Value = 0
17        timer.Text = "0.0"
18    end
19end

this is the script with the problem(Below)

01local gamie = game.ReplicatedStorage.Game
02local intro = game.ReplicatedStorage.Intro
03local timer = game.ReplicatedStorage.Timer
04lava = game.ReplicatedStorage.Lava
05local rs = game:GetService('ReplicatedStorage').Restart
06local t = game:GetService("ReplicatedStorage")
07 
08rs.Event:Connect(function(touch)
09        timer.Value = 20 -- this is supposed to change the value of the timer to 20 to count down but that wont change either...???
10    intro.Value = 1 --Part that is supposed to trigger timer(as shown in script above)
11    local clone = game.ReplicatedStorage.Lava2:Clone()
12    clone.Parent = game.Workspace      
13        if lava.Parent == game.ReplicatedStorage then
14            lava.Parent = game.Workspace
15        end
View all 24 lines...
0
And my game keeps lagging HARD it crashes studio Lamborghinihurican0 4 — 4y
0
yeah don’t use while true do use wait wait() do raid6n 2196 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Usually, you would want to avoid any loop with the wait() function or not. It is often best to use :GetPropertyChangedSignal(property) to fire the function rather than always check for a value. This will reduce the lag significantly as it only functions when the value is changed.

01timer = script.Parent
02val = game.ReplicatedStorage.Timer
03intro = game.ReplicatedStorage.Intro
04t = game.ReplicatedStorage.T
05 
06intro:GetPropertyChangedSignal("Value"):Connect(function()
07    if intro.Value == 1 then -- part that was referenced in script below
08        timer.Visible = true -- timer wont go visible
09        timer.Text = "0:"..val.Value
10    val.Value = val.Value - 1 -- timer wont go down a second
11    end
12    if timer.Text == "0:0" then -- this part works fine
13        local it = game:WaitForChild("ReplicatedStorage").It
14        it:FireServer()
15        timer.Visible = false
16        intro.Value = 0
17        timer.Text = "0.0"
18    end
19end)

Additionally, you should also use the tonumber() function just so the timer doesn’t break if text is entered into the text box. As for the final thing I noticed, you should probably put some data into the :FireServer() event so that the server can read the values of the timer and other data you sent.

Edit: I can’t fully help you because you didn’t paste the entirety of the scripts

0
although the long script in my question wont change the value of the timer and intro Lamborghinihurican0 4 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I don't know the full context of your situation or what your trying to do but i hope this helps. I would insert a NumberValue in your ScreenGui or really where ever you want just change the script according to your game and set the text to the NumberValue. I would also use a for loop instead of a while loop for your timer that you can call with a remote event when you want to use this. Again not sure if this is what you were looking for but I hope this can help in some way.

01game.ReplicatedStorage."Your remote event".OnClientEvent:Connect(function()--Instead of waiting for intro.Value == 1 call the timer using a remote event when you set the intro.Value to 1
02local seconds = script.Parent.Parent.Parent.Time --This is the NumberValue within the ScreenGUI
03local timer = script.Parent --The text label showing the time
04seconds.Value = 20
05script.Parent.Text = seconds.Value --This sets the Text to whatever the NumberValue is so changing it will change the text
06 
07for i = 1,seconds.Value do  --Use a for loop instead of a while loop
08    wait(1)
09        seconds.Value = seconds.Value - 1
10        script.Parent.Text = seconds.Value
11    end
12end)

Answer this question