Hi!
I came across a problem in my gui script. In this script I want the gui to be visible to me however it doesnt change. I’ve put out some print statements in this script to try to fix this problem however it looks like roblox studio just ignored the visibility script? Not sure if it is a bug or I wrote something wrong because on my title gui it worked fine.
Any help would be appreciated
outputs:
script:
TrailButton.MouseButton1Click:Connect(function()
print("Clicked")
local Titles = game.ReplicatedStorage.Trails
local example = game.ReplicatedStorage.GuiExamples.TrailExample
local scrollingFrame = TrailShop.ScrollingFrame
Instance.new("UIGridLayout",TrailShop.ScrollingFrame)
for i,v in pairs(Titles:GetChildren()) do
local insert = example:Clone()
insert.TrailName.Text = v.Name
insert.Name = v.Name
local result = OwnedTrails:FindFirstChild(v.Name)
local result2 = EquippedTrail:FindFirstChild(v.Name)
if result == nil then
insert.Event.Text = (v.Price.Value.." Tokens")
insert.Event.Name = "Buy"
elseif EquippedTrail.Value == v.Name then
insert.Event.Text = "Unequip"
insert.Event.Name = "Unequip"
else
insert.Event.Text = "Equip"
insert.Event.Name = "Equip"
end
insert.Parent = TrailShop.ScrollingFrame
end
local ytobe = scrollingFrame.UIGridLayout.AbsoluteContentSize.Y + 100
scrollingFrame.CanvasSize = UDim2.new(0, 0, 0, ytobe)
TrailShop.Visible = not TrailShop.Visible
print("it shld work")
if TrailShop.Visible == false then do
TrailShop.ScrollingFrame.UIGridLayout:Destroy()
print("done")
for i,v in pairs(TrailShop.ScrollingFrame:GetChildren()) do
v:Destroy()
end
end
end
end)
hello when the game is opened all the guis are moved to the PlayerGui and that might be the problem when you try to change the visibilty or any feature after the game started you should reffer it as PlayerGui.ScreenGui(or how its called).yourgui here is an example that i used
i first local the playergui:
However when I pressed the button neither did the gui from playergui nor startergui turned visible it simply just stayed the same. However I have another code from the same script that also runs the same code but it turns the gui visibility
TitleButton.MouseButton1Click:Connect(function()
local Titles = game.ReplicatedStorage.Titles
local example = game.ReplicatedStorage.GuiExamples.TitleExample
local scrollingFrame = TitleShop.ScrollingFrame
Instance.new("UIGridLayout",TitleShop.ScrollingFrame)
for i,v in pairs(Titles:GetChildren()) do
local insert = example:Clone()
insert.TitleName.TextColor3 = v.TextBox.TextColor3
insert.TitleName.Text = v.Name
insert.Name = v.Name
local result = OwnedTitles:FindFirstChild(v.Name)
local result2 = EquippedTitle:FindFirstChild(v.Name)
if result == nil then
insert.Event.Text = (v.Price.Value.." Tokens")
insert.Event.Name = "Buy"
elseif EquippedTitle.Value == v.Name then
insert.Event.Text = "Unequip"
insert.Event.Name = "Unequip"
else
insert.Event.Text = "Equip"
insert.Event.Name = "Equip"
end
insert.Parent = TitleShop.ScrollingFrame
end
TitleShop.Visible = not TitleShop.Visible
local ytobe = scrollingFrame.UIGridLayout.AbsoluteContentSize.Y + 100
scrollingFrame.CanvasSize = UDim2.new(0, 0, 0, ytobe)
TrailShop.Visible = false
for i,v in pairs(TrailShop.ScrollingFrame:GetChildren()) do
v:Destroy()
end
if TitleShop.Visible == false then do
TitleShop.ScrollingFrame.UIGridLayout:Destroy()
for i,v in pairs(TitleShop.ScrollingFrame:GetChildren()) do
v:Destroy()
end
end
end
end)
not working button:
TrailButton.MouseButton1Click:Connect(function()
print("Clicked")
local Titles = game.ReplicatedStorage.Trails
local example = game.ReplicatedStorage.GuiExamples.TrailExample
local scrollingFrame = TrailShop.ScrollingFrame
Instance.new("UIGridLayout",TrailShop.ScrollingFrame)
for i,v in pairs(Titles:GetChildren()) do
local insert = example:Clone()
insert.TrailName.Text = v.Name
insert.Name = v.Name
local result = OwnedTrails:FindFirstChild(v.Name)
local result2 = EquippedTrail:FindFirstChild(v.Name)
if result == nil then
insert.Event.Text = (v.Price.Value.." Tokens")
insert.Event.Name = "Buy"
elseif EquippedTrail.Value == v.Name then
insert.Event.Text = "Unequip"
insert.Event.Name = "Unequip"
else
insert.Event.Text = "Equip"
insert.Event.Name = "Equip"
end
insert.Parent = TrailShop.ScrollingFrame
end
local ytobe = scrollingFrame.UIGridLayout.AbsoluteContentSize.Y + 100
scrollingFrame.CanvasSize = UDim2.new(0, 0, 0, ytobe)
TrailShop.Visible = not TrailShop.Visible
print("it shld work")
if TrailShop.Visible == false then do
TrailShop.ScrollingFrame.UIGridLayout:Destroy()
print("done")
for i,v in pairs(TrailShop.ScrollingFrame:GetChildren()) do
v:Destroy()
end
end
end
end)
pretty sure both of them are fairly the same but only the other one works
No idea i was thinking that i put the variable wrongly but i dont think thats the case.
whole script:
wait(2)
local profile = script.Parent.Profile
local levellabel = profile.Level
local player = game.Players.LocalPlayer
local level = player.leaderstats.Level
local playervalues = player.PlayerValues
local exp = playervalues.exp
local exprequired = playervalues.Exprequired
local explabel = profile.Exp
local bar = profile.Exterior.Bar
local token = playervalues.Tokens
local currency = script.Parent.Currency
local AddButton = currency.Add
local CurrencyLabel = currency.Currency
local userId = player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = game.Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
local pfpimage = profile.pfp
local MainGui = script.Parent
local TitleButton = MainGui.TitleButton
local TrailButton = MainGui.TrailButton
local TitleShop = MainGui.TitleShop
local TrailShop = MainGui.TrailShop
local TitleInfo = MainGui.TitleInfo
local TrailInfo = MainGui.TrailInfo
local plr = game.Players.LocalPlayer
local OwnedTrails = plr.OwnedTrails
local OwnedTitles = plr.OwnedTitles
local EquippedTitle = plr.EquippedTitle
local EquippedTrail = plr.EquippedTrail
local GuiExamples = game.ReplicatedStorage.GuiExamples
levellabel.Text = "Level: "..level.Value
explabel.Text = exp.Value.."/"..exprequired.Value
bar.Size = UDim2.new(exp.Value/exprequired.Value,0,1,0)
pfpimage.Image = content
CurrencyLabel.Text = token.Value
level.Changed:Connect(function()
levellabel.Text = "Level: "..level.Value
end)
exp.Changed:Connect(function()
explabel.Text = exp.Value.."/"..exprequired.Value
bar.Size = UDim2.new(exp.Value/exprequired.Value,0,1,0)
end)
token.Changed:Connect(function()
CurrencyLabel.Text = token.Value
end)
TrailButton.MouseEnter:Connect(function()
TrailInfo.Visible = true
end)
TrailButton.MouseLeave:Connect(function()
TrailInfo.Visible = false
end)
TitleButton.MouseEnter:Connect(function()
TitleInfo.Visible = true
end)
TitleButton.MouseLeave:Connect(function()
TitleInfo.Visible = false
end)
TrailButton.MouseButton1Click:Connect(function()
TrailShop.Visible = not TrailShop.Visible
TitleShop.Visible = false
end)
TitleButton.MouseButton1Click:Connect(function()
local Titles = game.ReplicatedStorage.Titles
local example = game.ReplicatedStorage.GuiExamples.TitleExample
local scrollingFrame = TitleShop.ScrollingFrame
Instance.new("UIGridLayout",TitleShop.ScrollingFrame)
for i,v in pairs(Titles:GetChildren()) do
local insert = example:Clone()
insert.TitleName.TextColor3 = v.TextBox.TextColor3
insert.TitleName.Text = v.Name
insert.Name = v.Name
local result = OwnedTitles:FindFirstChild(v.Name)
local result2 = EquippedTitle:FindFirstChild(v.Name)
if result == nil then
insert.Event.Text = (v.Price.Value.." Tokens")
insert.Event.Name = "Buy"
elseif EquippedTitle.Value == v.Name then
insert.Event.Text = "Unequip"
insert.Event.Name = "Unequip"
else
insert.Event.Text = "Equip"
insert.Event.Name = "Equip"
end
insert.Parent = TitleShop.ScrollingFrame
end
TitleShop.Visible = not TitleShop.Visible
local ytobe = scrollingFrame.UIGridLayout.AbsoluteContentSize.Y + 100
scrollingFrame.CanvasSize = UDim2.new(0, 0, 0, ytobe)
TrailShop.Visible = false
for i,v in pairs(TrailShop.ScrollingFrame:GetChildren()) do
v:Destroy()
end
if TitleShop.Visible == false then do
TitleShop.ScrollingFrame.UIGridLayout:Destroy()
for i,v in pairs(TitleShop.ScrollingFrame:GetChildren()) do
v:Destroy()
end
end
end
end)
TrailButton.MouseButton1Click:Connect(function()
print("Clicked")
local Titles = game.ReplicatedStorage.Trails
local example = game.ReplicatedStorage.GuiExamples.TrailExample
local scrollingFrame = TrailShop.ScrollingFrame
Instance.new("UIGridLayout",TrailShop.ScrollingFrame)
for i,v in pairs(Titles:GetChildren()) do
local insert = example:Clone()
insert.TrailName.Text = v.Name
insert.Name = v.Name
local result = OwnedTrails:FindFirstChild(v.Name)
local result2 = EquippedTrail:FindFirstChild(v.Name)
if result == nil then
insert.Event.Text = (v.Price.Value.." Tokens")
insert.Event.Name = "Buy"
elseif EquippedTrail.Value == v.Name then
insert.Event.Text = "Unequip"
insert.Event.Name = "Unequip"
else
insert.Event.Text = "Equip"
insert.Event.Name = "Equip"
end
insert.Parent = TrailShop.ScrollingFrame
end
local ytobe = scrollingFrame.UIGridLayout.AbsoluteContentSize.Y + 100
scrollingFrame.CanvasSize = UDim2.new(0, 0, 0, ytobe)
TrailShop.Visible = not TrailShop.Visible
print("it shld work")
if TrailShop.Visible == false then do
TrailShop.ScrollingFrame.UIGridLayout:Destroy()
print("done")
for i,v in pairs(TrailShop.ScrollingFrame:GetChildren()) do
v:Destroy()
end
end
end
end)