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

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

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!

2 comments

0

pause the tweens?

0

You called the function seasonchange! It doesnt return a function and therefor will error.

1 answer

✓ Accepted answer
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)

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