Hey! I’m experiencing an error in some of my GUI code and was wondering if anyone could help me work out what’s causing it and how to fix it. Error & code is below. Thanks!
Error:
Script:
local FillTween = TweenService:Create(script.Parent.Level.Bar, TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = UDim2.new(1, 0,1, 0)})
script.Parent.Button.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
end)
Other relevant code in the script:
script.Parent.Button.Image.MouseButton1Up:Connect(function()
MouseBeingHeldDown = false
FillTween:Pause()
end)
script.Parent.Button.Text.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
end)
script.Parent.Button.Text.MouseButton1Up:Connect(function()
MouseBeingHeldDown = false
script.Parent.Button:TweenSize(UDim2.new(0, 76,0, 76),"Out","Linear",0.1,true)
script.Parent.Button.Image:TweenSize(UDim2.new(0, 40,0, 40),"Out","Linear",0.1,true)
FillTween:Pause()
end)
script.Parent.Button.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
print("done")
end)
script.Parent.Button.MouseButton1Up:Connect(function()
MouseBeingHeldDown = false
FillTween:Pause()
end)
script.Parent.Button.Image.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
end)
I also have some other code that does stuff when the Tween is paused, completed, began, etc. Let me know if you need it.
1 Like
either the button is not loaded in yet (use WaitForChild) or you just have the wrong path, so double check that is the path to the button in your explorer
also instead of MouseButton1Down use Activated, because players on mobile can’t use buttons that use MouseButton1Down or any MouseButton function and this is due to the event receiving input through the mouse
Trulineo
(4O4)
December 20, 2021, 12:04pm
3
It says “attempt to index nil with connect” are you positive youre connecting to a button?
2 Likes
Why are you not declaring your pathways?
local plr = game.Players.LocalPlayer
local PlayerGui = plr:WaitForChild(“PlayerGui”)
local FillTween = TweenService:Create(script.Parent.Level.Bar, TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = UDim2.new(1, 0,1, 0)})
script.Parent:WaitForChild("Button").MouseButton1Down:Connect(function() -- Make sure it is loaded
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
end)
1 Like
Positive! (charssssssssssssssssssss)
1 Like
Update: I believe it’s being caused by another one of the Mouse events being fired off the same button as when I disable these the error disappears.
local plr = game.Players.LocalPlayer
local PlayerGui = plr:WaitForChild("PlayerGui")
local BatterStationGui = PlayerGui:FindFirstChild("BatterStationGui")
local Button = BatterStationGui:FindFirstChild("Button")
Button.MouseButton1Down:Connect(function() -- Make sure it is loaded
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
end)
Trulineo
(4O4)
December 20, 2021, 12:10pm
9
When testing go to players and check under your characters PlayerGui to see if the button is still there
I’ve updated the main post with the other relevant code in the script.
1 Like
Yes, but the error you are showing, is due to you not declaring the button properly.
Wait, I think it’s because it’s not visible, let me just confirm.
Please try this
local plr = game.Players.LocalPlayer
local FillTween = TweenService:Create(script.Parent.Level.Bar, TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = UDim2.new(1, 0,1, 0)})
local PlayerGui = plr:WaitForChild("PlayerGui")
local BatterStationGui = PlayerGui:FindFirstChild("BatterStationGui")
local Button = BatterStationGui:FindFirstChild("Button")
Button.Image.MouseButton1Up:Connect(function()
MouseBeingHeldDown = false
FillTween:Pause()
end)
Button.Text.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
end)
Button.Text.MouseButton1Up:Connect(function()
MouseBeingHeldDown = false
script.Parent.Button:TweenSize(UDim2.new(0, 76,0, 76),"Out","Linear",0.1,true)
script.Parent.Button.Image:TweenSize(UDim2.new(0, 40,0, 40),"Out","Linear",0.1,true)
FillTween:Pause()
end)
Button.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
print("done")
end)
Button.MouseButton1Up:Connect(function()
MouseBeingHeldDown = false
FillTween:Pause()
end)
Button.Image.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
end)
Trulineo
(4O4)
December 20, 2021, 12:13pm
14
why do you have 5 events connected to the button?
@Xynterical charssssssssssssssssssss
You’re supposed to be able to hold it in and it’ll fill up a bar, tweening the size of it.
Will do! (charssssssssssssssssssss)
Xynterical:
local plr = game.Players.LocalPlayer
local FillTween = TweenService:Create(script.Parent.Level.Bar, TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = UDim2.new(1, 0,1, 0)})
local PlayerGui = plr:WaitForChild("PlayerGui")
local BatterStationGui = PlayerGui:FindFirstChild("BatterStationGui")
local Button = BatterStationGui:FindFirstChild("Button")
Button.Image.MouseButton1Up:Connect(function()
MouseBeingHeldDown = false
FillTween:Pause()
end)
Button.Text.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
end)
Button.Text.MouseButton1Up:Connect(function()
MouseBeingHeldDown = false
script.Parent.Button:TweenSize(UDim2.new(0, 76,0, 76),"Out","Linear",0.1,true)
script.Parent.Button.Image:TweenSize(UDim2.new(0, 40,0, 40),"Out","Linear",0.1,true)
FillTween:Pause()
end)
Button.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
print("done")
end)
Button.MouseButton1Up:Connect(function()
MouseBeingHeldDown = false
FillTween:Pause()
end)
Button.Image.MouseButton1Down:Connect(function()
MouseBeingHeldDown = true
while MouseBeingHeldDown == true do
script.Parent.Level.Bar.BackgroundTransparency = 0
FillTween:Play()
wait()
end
end)
Nope, sadly the error is persisting.
Do you still have the same error?
charssssssssssssssssssssssssssssssssssssss