I’m currently in the process of making a menu system for my project, where each act is laid out in a GUI and clicking on the act will reveal information about it and the name, along with a join button. Clicking the join button works, but it teleports the player to the wrong place and overall displays the incorrect data.
In the attached video, you can see I clicked on Act 1, it displays the correct description and name for the act, but when I press the Join button, it teleports me to Act 2.
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local TeleportService = game:GetService("TeleportService")
local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")
local player = Players.LocalPlayer
local PlayerGui = player.PlayerGui
local gui = script.Parent
local pages = gui.Pages
local actsMenu = pages.Acts
local GamesGrid = actsMenu.GamesGrid
local template = GamesGrid.Template
--// GUI CONSTANTS
local container = gui.Container
local Sounds = gui.Sounds
local ActInfo = actsMenu.ActInfo
local ActDescriptionBox = ActInfo.Description
local ActImage = ActInfo.Template
local JoinButton = ActInfo.TextButton
local ActRegistry = require(ReplicatedStorage.ActsRegistry)
local ChapterOneActs = ActRegistry.Chapter1Acts
local acts = {}
local currentActTypewriter = false
local currenttypewriterName = nil
local currenttypewriterDesc = nil
local currentimageChange = nil
--// Typewriter functions
local function typewriterName(fullText)
local Length = #fullText
local TimeToTake = Length / 30
local accumulated = 0
while TimeToTake > accumulated do
accumulated += RunService.Heartbeat:Wait()
ActDescriptionBox.Title.TextLabel.Text = string.sub(fullText, 1, math.floor((accumulated / TimeToTake) * Length))
end
end
local function typewriterDesc(fullText)
local Length = #fullText
local TimeToTake = Length / 30
local accumulated = 0
while TimeToTake > accumulated do
accumulated += RunService.Heartbeat:Wait()
ActDescriptionBox.DescriptionText.Text = string.sub(fullText, 1, math.floor((accumulated / TimeToTake) * Length))
end
end
local function imageChange(act)
print("Running image change")
local staticIn = TweenService:Create(ActImage.Static, TweenInfo.new(0.5), { ImageTransparency = 0 })
staticIn:Play()
staticIn.Completed:Wait()
ActImage.PreviewImage.Image = act.PreviewImageId
task.wait(1)
if act.ShowsImage == true then
local staticOut = TweenService:Create(ActImage.Static, TweenInfo.new(1), { ImageTransparency = 1 })
staticOut:Play()
end
end
local function populateActInfo(act)
if currentActTypewriter ~= false then
currentActTypewriter = nil
coroutine.yield(currenttypewriterName)
coroutine.yield(currenttypewriterDesc)
coroutine.yield(currentimageChange)
end
if act.CanJoin == false then
JoinButton.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
else
JoinButton.BackgroundColor3 = Color3.fromRGB(0, 93, 0)
end
currenttypewriterDesc = coroutine.create(typewriterDesc)
coroutine.resume(currenttypewriterDesc, act.ActDescription)
currenttypewriterName = coroutine.create(typewriterName)
coroutine.resume(currenttypewriterName, "// ACT " .. act.ActNumber .. ": " .. act.ActName)
currentimageChange = coroutine.create(imageChange)
coroutine.resume(currentimageChange, act)
currentActTypewriter = true
end
local function joinEffect(act)
print("Joining Act:", act.ActNumber) -- Debugging output
local saharaosGUI = PlayerGui.SaharaOS
local SaharaOSContainer = saharaosGUI.Content
if act.CanJoin == true then
Sounds.saharaos:Play()
gui.Enabled = false
saharaosGUI.Enabled = true
SaharaOSContainer.ActTitle.Text = "ACT " .. act.ActNumber .. ": " .. act.ActName
local scanlinesfadein = TweenService:Create(saharaosGUI.scanlines, TweenInfo.new(1), { ImageTransparency = 0.2 })
local musicfadeout = TweenService:Create(SoundService.MenuMusic, TweenInfo.new(1), { Volume = 0 })
musicfadeout:Play()
scanlinesfadein:Play()
scanlinesfadein.Completed:Wait()
for i, item in pairs(SaharaOSContainer:GetChildren()) do
if item:IsA("GuiObject") then
if not item.Visible then
item.Visible = true
SaharaOSContainer.beep:Play()
SaharaOSContainer.beep.PlaybackSpeed += .1
task.wait(0.1)
end
end
end
task.wait(2)
local CustomTeleportGui = ReplicatedStorage.CustomTeleport
TeleportService:SetTeleportGui(CustomTeleportGui)
CustomTeleportGui.Parent = Players.LocalPlayer.PlayerGui
TeleportService:Teleport(act.PlaceId, Players.LocalPlayer)
end
end
--// GET ALL ACTS
for actKey, act in pairs(ChapterOneActs) do
table.insert(acts, act)
print(act)
print(acts)
local newTemplate = template:Clone()
newTemplate.Act.Value = act.ActNumber
local actNameButton = newTemplate.ActNameButton
local previewImage = newTemplate.PreviewImage
local actJoinButton = ActInfo.TextButton
actNameButton.Text = "ACT " .. act.ActNumber .. ": " .. act.ActName
previewImage.Image = act.PreviewImageId
newTemplate.LayoutOrder = act.ActNumber
newTemplate.Parent = GamesGrid
newTemplate.Visible = true
actNameButton.MouseButton1Click:Connect(function()
populateActInfo(act)
end)
actJoinButton.MouseButton1Click:Connect(function()
print("Join button clicked for Act:", act.ActNumber) -- Debugging output
joinEffect(act)
end)
previewImage.MouseButton1Click:Connect(function()
populateActInfo(act)
end)
end
I added a couple print statements for debugging, here’s what is being printed when I click the join button.
23:10:04.841 Join button clicked for Act: 1 - Client - LocalScript:174 23:10:04.841 Joining Act: 1 - Client - LocalScript:102 23:10:04.842 Join button clicked for Act: 3 - Client - LocalScript:174 23:10:04.842 Joining Act: 3 - Client - LocalScript:102 23:10:04.842 Join button clicked for Act: 2 - Client - LocalScript:174 23:10:04.842 Joining Act: 2 - Client - LocalScript:102