Using IF and ELSEIF statements, tween doenst play

Hello there,
i want to tween a scrolling frame, the canvasPosition which is a Vector2. Ive tried everything. Tweening it with out any if statements and the ordered integer thingy it works, but if i use some sort of “integers” (chances) and if statements then it does not work. Take a look:

local Chances = {
	["Backwards Royal Cappy"] = 750, -- 75
	["next Backwards Royal Cappy"] = 750, -- 75
	["next next Backwards Royal Cappy"] = 750, -- 75
	["next next next Backwards Royal Cappy"] = 750, -- 75
	["Legendary Roblox Tie"] = 100, -- 10
	["next Legendary Roblox Tie"] = 100, -- 10
	["Mythical Frozen Horns"] = 5, -- 0.5
}

local function RandomFromWeightedTable(OrderedTable)
	local TotalWeight = 0

	for Piece, Weight in pairs(OrderedTable) do
		TotalWeight += Weight
	end

	local Chance = Random.new():NextInteger(1, TotalWeight)

	local Counter = 0

	for Piece, Weight in pairs(OrderedTable) do
		Counter += Weight

		if Chance <= Counter then
			return Piece
		end
	end
end

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Parent.Parent.CaseOpening.Visible = true
	script.Parent.Parent.Parent.Parent.Visible = false
	local OrderedInteger = RandomFromWeightedTable(Chances)
print(OrderedInteger) -- Tried to implement a print method for the Chance
	if OrderedInteger == "Backwards Royal Cappy" then
		game:GetService("TweenService"):Create(game.StarterGui.UI.Dashboard.CaseOpening.MainOpenBLUE.ScrollingFrame, TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 1, false, 0.5), {CanvasPosition = Vector2.new(450, 0)}):Play()
	elseif OrderedInteger == "next Backwards Royal Cappy" then
		game:GetService("TweenService"):Create(game.StarterGui.UI.Dashboard.CaseOpening.MainOpenBLUE.ScrollingFrame, TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 1, false, 0.5), {CanvasPosition = Vector2.new(1050, 0)}):Play()
	elseif OrderedInteger == "next next Backwards Royal Cappy" then
		game:GetService("TweenService"):Create(game.StarterGui.UI.Dashboard.CaseOpening.MainOpenBLUE.ScrollingFrame, TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 1, false, 0.5), {CanvasPosition = Vector2.new(1500, 0)}):Play()
	elseif OrderedInteger == "next next next Backwards Royal Cappy" then
		game:GetService("TweenService"):Create(game.StarterGui.UI.Dashboard.CaseOpening.MainOpenBLUE.ScrollingFrame, TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 1, false, 0.5), {CanvasPosition = Vector2.new(2400, 0)}):Play()
	elseif OrderedInteger == "Legendary Roblox Tie" then
		game:GetService("TweenService"):Create(game.StarterGui.UI.Dashboard.CaseOpening.MainOpenBLUE.ScrollingFrame, TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 1, false, 0.5), {CanvasPosition = Vector2.new(2130, 0)}):Play()
	elseif OrderedInteger == "next Legendary Roblox Tie" then
		game:GetService("TweenService"):Create(game.StarterGui.UI.Dashboard.CaseOpening.MainOpenBLUE.ScrollingFrame, TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 1, false, 0.5), {CanvasPosition = Vector2.new(2580, 0)}):Play()
	elseif OrderedInteger == "Mythical Frozen Horns" then
		game:GetService("TweenService"):Create(game.StarterGui.UI.Dashboard.CaseOpening.MainOpenBLUE.ScrollingFrame, TweenInfo.new(4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 1, false, 0.5), {CanvasPosition = Vector2.new(850, 0)}):Play()
	elseif not OrderedInteger then
		print(OrderedInteger..": Error while tweening")
	end
end)	

The error does not print in the last line. But it doenst tween but shows the gui and makes it visible.

It prints the chance, well. It does not tween!
Screenshot_79

You’re tweening the frame in the StarterGui which is not viewable to the player. I’m not sure if tweens work in non physical spaces like Workspace/Lighting/Storage.

You also may want to check if the value you’re printing is actually a string, you can use type(OrderedInteger) or typeof(OrderedInteger) to find out.

Also as a reminder, StarterGuis clone everything in it to the parent of a Player’s PlayerGui. If you want to access the GUI inside of a player, go to game.Players.PlayerName.PlayerGui.

2 Likes

Finally! Thank you so much!