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 3 years ago

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

timer = script.Parent 
val = game.ReplicatedStorage.Timer
intro = game.ReplicatedStorage.Intro
t = game.ReplicatedStorage.T

while true do
    if intro.Value == 1 then -- part that was referenced in script below
        timer.Visible = true -- timer wont go visible
        timer.Text = "0:"..val.Value
    val.Value = val.Value - 1 -- timer wont go down a second
    end
    if timer.Text == "0:0" then -- this part works fine
        local it = game:WaitForChild("ReplicatedStorage").It
        it:FireServer()
        timer.Visible = false
        intro.Value = 0
        timer.Text = "0.0"
    end
end

this is the script with the problem(Below)

local gamie = game.ReplicatedStorage.Game
local intro = game.ReplicatedStorage.Intro
local timer = game.ReplicatedStorage.Timer
lava = game.ReplicatedStorage.Lava
local rs = game:GetService('ReplicatedStorage').Restart 
local t = game:GetService("ReplicatedStorage")

rs.Event:Connect(function(touch)
        timer.Value = 20 -- this is supposed to change the value of the timer to 20 to count down but that wont change either...???
    intro.Value = 1 --Part that is supposed to trigger timer(as shown in script above)
    local clone = game.ReplicatedStorage.Lava2:Clone()
    clone.Parent = game.Workspace       
        if lava.Parent == game.ReplicatedStorage then 
            lava.Parent = game.Workspace
        end
        wait(1)
        if lava.Parent == game.Workspace then
            lava.Parent = game.ReplicatedStorage
        end
    wait(3)
    clone:Destroy()
    local tp = game.ReplicatedStorage.TP
    tp.Parent = game.Workspace
end)

0
And my game keeps lagging HARD it crashes studio Lamborghinihurican0 4 — 3y
0
yeah don’t use while true do use wait wait() do raid6n 2196 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 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.

timer = script.Parent 
val = game.ReplicatedStorage.Timer
intro = game.ReplicatedStorage.Intro
t = game.ReplicatedStorage.T

intro:GetPropertyChangedSignal("Value"):Connect(function()
    if intro.Value == 1 then -- part that was referenced in script below
        timer.Visible = true -- timer wont go visible
        timer.Text = "0:"..val.Value
    val.Value = val.Value - 1 -- timer wont go down a second
    end
    if timer.Text == "0:0" then -- this part works fine
        local it = game:WaitForChild("ReplicatedStorage").It
        it:FireServer()
        timer.Visible = false
        intro.Value = 0
        timer.Text = "0.0"
    end
end)

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 — 3y
Ad
Log in to vote
0
Answered by 3 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.

game.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
local seconds = script.Parent.Parent.Parent.Time --This is the NumberValue within the ScreenGUI
local timer = script.Parent --The text label showing the time
seconds.Value = 20 
script.Parent.Text = seconds.Value --This sets the Text to whatever the NumberValue is so changing it will change the text

for i = 1,seconds.Value do  --Use a for loop instead of a while loop 
    wait(1)
        seconds.Value = seconds.Value - 1
        script.Parent.Text = seconds.Value
    end
end)

Answer this question