I am making a system where when you press a button it takes you to a world but it cycles through it and its not working
local player = game.Players.LocalPlayer
local char = player.Character
local rep = game:GetService("ReplicatedStorage")
local event = rep:WaitForChild("WorldChange", 5)
local allchar = char:GetChildren()
local serverstorage = game:GetService("Workspace")
local tele = serverstorage:WaitForChild("Tele")
function MainWorld()
script.Parent.Current.Text = "Main World"
script.Parent.Last.Text = "shadow World"
script.Parent.Next.Text = "hidden World"
script.Parent.Left.MouseButton1Click:Connect(function()
ShadowWorld()
end)
script.Parent.Right.MouseButton1Click:Connect(function()
HiddenWorld()
end)
if tele then
char.LowerTorso.CFrame = CFrame.new(tele.Position)
else
print("its nil")
end
end
function ShadowWorld()
script.Parent.Current.Text = "Shadow World"
script.Parent.Last.Text = "hidden World"
script.Parent.Next.Text = "main World"
script.Parent.Left.MouseButton1Click:Connect(function()
HiddenWorld()
end)
script.Parent.Right.MouseButton1Click:Connect(function()
MainWorld()
end)
end
function HiddenWorld()
script.Parent.Current.Text = "Hidden World"
script.Parent.Last.Text = "main World"
script.Parent.Next.Text = "shadow World"
script.Parent.Left.MouseButton1Click:Connect(function()
MainWorld()
end)
script.Parent.Right.MouseButton1Click:Connect(function()
ShadowWorld()
end)
end
MainWorld()
i am not getting any errors and the things that are happening are,
when i press the button to go to the hidden world, it works but after that if i try to go to the shadow world it does not work and runs the code for the main world, and if i press main then it does the shadow world and normally crashes my game
please help i cant fix it

1 comment
please dont make it listen do a button click in each function, only do it ONE time like the way i wrote it, then cal leach function and if you want, you can make a variable similar to debounce to let them change worlds or not