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

Function only runs once even though it should run multiple times?

Asked by 4 years ago

Hello, I have been trying to create a system that "changes the season" as seen below, and create a function for a prompt that appears when the season changes, or well should change. What happens is that it runs once, displays "SUMMER" correctly, then once another background script changes the value of the season, it doesnt appear again unless i kill my character and respawn, which again makes it play once more and then never again.

local Season = workspace.DaysSeasons.Season

local function seasonchange(Season)
    local object = script.Parent
    if Season == "SUMMER" then
        object.Text = "SUMMER"
    elseif Season == "AUTUMN" then
        object.Text = "AUTUMN"
    elseif Season == "WINTER" then
        object.Text = "WINTER"
    elseif Season == "SPRING" then
        object.Text = "SPRING"
    end
    if Season == "SUMMER" then
        object.TextColor3 = Color3.fromRGB(255, 183, 0)
    elseif Season == "AUTUMN" then
        object.TextColor3 = Color3.fromRGB(147, 98, 94)
    elseif Season == "WINTER" then
        object.TextColor3 = Color3.fromRGB(170, 255, 255)
    elseif Season == "SPRING" then
        object.TextColor3 = Color3.fromRGB(170, 255, 127)
    end
    object:TweenPosition(UDim2.new(11.49, 0,3.83, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Bounce)
    wait(4)
    object:TweenPosition(UDim2.new(14.49, 0,3.83, 0))
    wait()
    object.Position = UDim2.new(11.49, 0,-1, 0)
end

Season.Value.changed:Connect(seasonchange(Season.Value))

after trying several things ive found that remvoing this line

object:TweenPosition(UDim2.new(14.49, 0,3.83, 0))

shows me that the first tween just keep on replaying? the textlabel's positon is changed here

object.Position = UDim2.new(11.49, 0,-1, 0)

But apparently the tween just keeps on going and probably making the function never end? I cannot understand why it acts like that, any help is appreciated!

0
pause the tweens? matiss112233 258 — 4y
0
You called the function seasonchange! It doesnt return a function and therefor will error. herrtt 387 — 4y

1 answer

Log in to vote
0
Answered by
iuclds 720 Moderation Voter
4 years ago
local Season = workspace.DaysSeasons.Season

local function seasonchange(Season)
    local object = script.Parent
    if Season == "SUMMER" then
        object.Text = "SUMMER"
    elseif Season == "AUTUMN" then
        object.Text = "AUTUMN"
    elseif Season == "WINTER" then
        object.Text = "WINTER"
    elseif Season == "SPRING" then
        object.Text = "SPRING"
    end
    if Season == "SUMMER" then
        object.TextColor3 = Color3.fromRGB(255, 183, 0)
    elseif Season == "AUTUMN" then
        object.TextColor3 = Color3.fromRGB(147, 98, 94)
    elseif Season == "WINTER" then
        object.TextColor3 = Color3.fromRGB(170, 255, 255)
    elseif Season == "SPRING" then
        object.TextColor3 = Color3.fromRGB(170, 255, 127)
    end
    object:TweenPosition(UDim2.new(11.49, 0,3.83, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Bounce)
    wait(4)
    object:TweenPosition(UDim2.new(14.49, 0,3.83, 0))
    wait()
    object.Position = UDim2.new(11.49, 0,-1, 0)
end

Season:GetPropertyChangedSignal('Value'):Connect(function()
    seasonchange(Season.Value)
end)
Ad

Answer this question