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

When I put in else it breaks my script or makes it not work?

Hello. I am making this script where you have to be a certain rank in the group to make the code work. It works however, I can't find where to put the else.

Because I want to make it so if you try and click it and you are not that rank, it says that. When I try to put else, it usually breaks it. If you could help that would be great.

Just to be clear, I want the full script to run if the player is ranked appropriately in the group but if they are not, for example, let's say it would JUST run "last.Text = "You do not own this.""

local player = game.Players.LocalPlayer
local classes = script.Parent.Parent.Parent.Parent.Classes
local last = script.Parent.Parent.Parent.Parent.End

script.Parent.MouseButton1Click:connect(function()
		if player:GetRankInGroup(2696060) == 5 then
		classes:TweenPosition(UDim2.new(0.99, 0,0.116, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.7, false, function()
		wait(1.3)
		last:TweenPosition(UDim2.new(0.131, 0, 0.116, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.7, false, function()
			
		game.ReplicatedStorage:FindFirstChild('Eco')
		if game.ReplicatedStorage:FindFirstChild('Eco') then
			game.ReplicatedStorage.Eco:Clone().Parent = player.Backpack
			
				

		end 
		
		end)
		end)
		end
		
	
end)

1 answer

✓ Accepted answer
local player = game.Players.LocalPlayer
local classes = script.Parent.Parent.Parent.Parent.Classes
local last = script.Parent.Parent.Parent.Parent.End

script.Parent.MouseButton1Click:connect(function()
        if player:GetRankInGroup(2696060) == 5 then
            classes:TweenPosition(
                UDim2.new(0.99, 0, 0.116, 0),
                Enum.EasingDirection.Out,
                Enum.EasingStyle.Linear,
                0.7,
                false,
                function()
                    wait(1.3)
                    last:TweenPosition(
                        UDim2.new(0.131, 0, 0.116, 0),
                        Enum.EasingDirection.Out,
                        Enum.EasingStyle.Linear,
                        0.7,
                        false,
                        function()
				local eco = game.ReplicatedStorage:FindFirstChild("Eco")
				if eco then
					eco:Clone().Parent = player.Backpack
				end
                        end)
                end)
	else
		-- If their rank ~= 5
	end
end)

It helps to indent your code properly, then you can find exactly where the if statement ends, and put you 'else' and 'elseif' in the correct place. You can use tools like: https://goonlinetools.com/lua-beautifier/ to do this, however it's better just to indent it properly from the start.

Also I'd recommend running checks in your callbacks incase the button has been clicked again before the previous callbacks have finished tweening.

Fyi, the website seems to be killing the indentation in that last callback, so excuse the weird formatting

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