I want to make my own 100% working tutorial from scratch for my experience.
Although it works on tactile screen devices, on PC doesn’t. When pressing E, the key for going to next page, it destroys all of them, and I don’t know what to do.
this is the script of the tutorial’s first pages on PC
local mainpage = script.Parent.Parent
local button = script.Parent
local skipsound = script.Parent.Parent.Parent.Skipsound
local nextpage = script.Parent.Parent.Parent.PAGINA2 --La página que se muestra al ejecutar la función
mainpage.Visible = true
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
skipsound:Play()
mainpage.Visible = false
nextpage.Visible = true
end
end)
and this is the last page’s
local mainpage = script.Parent.Parent
local button = script.Parent
local skipsound = script.Parent.Parent.Parent.Skipsound
local nextpage = script.Parent.Parent.Parent.PAGINA5 --La página que se muestra al ejecutar la función
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
skipsound:Play()
mainpage.Visible = false
script.Parent.Parent.Parent:Destroy()
end
end)
I think the issue here is in InputBegan event. It’s triggering for multiple scripts at once, causing all the pages to be destroyed when the ‘E’ key is pressed.
First Page Script:
local mainpage = script.Parent.Parent
local button = script.Parent
local skipsound = script.Parent.Parent.Parent.Skipsound
local nextpage = script.Parent.Parent.Parent.PAGINA2 -- La página que se muestra al ejecutar la función
mainpage.Visible = true
local uis = game:GetService("UserInputService")
local function onInputBegan(input)
if input.KeyCode == Enum.KeyCode.E then
skipsound:Play()
mainpage.Visible = false
nextpage.Visible = true
uis.InputBegan:Disconnect(onInputBegan) -- disconnect the event to prevent multiple triggers
end
end
uis.InputBegan:Connect(onInputBegan)
Last Page Script
local mainpage = script.Parent.Parent
local button = script.Parent
local skipsound = script.Parent.Parent.Parent.Skipsound
local nextpage = script.Parent.Parent.Parent.PAGINA5 -- La página que se muestra al ejecutar la función
local uis = game:GetService("UserInputService")
local function onInputBegan(input)
if input.KeyCode == Enum.KeyCode.E then
skipsound:Play()
mainpage.Visible = false
script.Parent.Parent.Parent:Destroy()
uis.InputBegan:Disconnect(onInputBegan) -- disconnect the event to prevent multiple triggers
end
end
uis.InputBegan:Connect(onInputBegan)
Also if this does not work, would you mind sharing your GUI setup?
I tried your code in the pages of my tutorial. And making sure I copied correctly. But still shows me this. robloxapp-20240712-1311543.wmv (1.5 MB)
I don’t know what do you mean with GUI setup. But here’s a screenshot of the tutorial in the explorer with the properties of the elements.
Tutorial in the explorer
As I said earlier, the problem is in E key.
When player presses E key, all of the scripts are running at the same time, so it just skips to the end and destroys the ScreenGui.
So I disabled all of the localscripts except first one
local mainpage = script.Parent.Parent
local button = script.Parent
local nextpage = script.Parent.Parent.Parent.Frame2
local uis = game:GetService("UserInputService")
local function onInputBegan(input)
if input.KeyCode == Enum.KeyCode.E then
mainpage.Visible = false
nextpage.Visible = true
nextpage.TextButton.LocalScript.Enabled = true
end
end
uis.InputBegan:Connect(onInputBegan)
I just have done that, but now the problem is than instead of destroying the ScreenGui, it lets me go to next page but from there I can’t go any further. Maybe it’s because in every Button there are 2 scripts: The one for PC users and the other for mobile users.
Footage here robloxapp-20240712-1352233.wmv (1.1 MB)
In that case I made this universal script for all of the pages you have:
local screenGui = script.Parent
local uis = game:GetService("UserInputService")
local currentPageIndex = 1
local totalPages = 5 -- total number of frames
local function showPage(index)
for i = 1, totalPages do
local page = screenGui:FindFirstChild("Frame" .. i)
if page then
page.Visible = (i == index)
end
end
end
local function onInputBegan(input)
if input.KeyCode == Enum.KeyCode.E then
-- input sound here
if currentPageIndex < totalPages then
currentPageIndex = currentPageIndex + 1
showPage(currentPageIndex)
else
-- last frame logic
screenGui:Destroy()
end
end
end
uis.InputBegan:Connect(onInputBegan)
-- show the first when loaded
showPage(currentPageIndex)
Setup should look like this:
You can add in frames anything you want but make sure that frames are named like in screenshot or if you want to rename it change this line of code:
local page = screenGui:FindFirstChild("Frame" .. i)
For example, if you want your frames to be named Page
Code will look like this:
local page = screenGui:FindFirstChild("Page" .. i)
But again, make sure that frames are named correctly with numbers as in screenshot.
I just noticed my tutorial is already adapted to mobile, so maybe I should just delete the ‘pc’ LocalScripts and paste the universal one to the screenGui. Should I?