Hello, I am struggling to have the banana gui move left and right. it currently is not moving at all. Any help is appreciated.
CD.MouseClick:Connect(function()
ScreenGUI.Enabled = true
end)
while true do
if ScreenGUI.Enabled == true then
if Banana.Position == Vector2.new(0.0, 0.046, 0.0) then
Direction = "Right"
else if Banana.Position == Vector2.new(0.895, 0.046, 0.0) then
Direction = "Left"
end
end
if Direction == "Right" then
Banana:TweenPosition(UDim2.new(Banana.Position.X + 0.005, 0.046, 0),"Out","Sine",1)
else if Direction == "Left" then
Banana:TweenPosition(UDim2.new(Banana.Position.X - 0.005, 0.046, 0),"Out","Sine",1)
end
end
end
wait(0.01)
end
This is the error message: Players.Puppy_lovertheawsome.PlayerGui.ScreenGui.MainFrame.WorkFrame.Banana.LocalScript:22: invalid argument #2 (UDim expected, got number)
local CD = script.Parent
local ScreenGUI = CD.Parent
local Banana = ScreenGUI.MainFrame.WorkFrame.Banana
local Direction = "Right"
CD.MouseClick:Connect(function()
ScreenGUI.Enabled = true
end)
while true do
if ScreenGUI.Enabled == true then
if Banana.Position == UDim2.new(0, 0.046, 0, 0) then
Direction = "Right"
elseif Banana.Position == UDim2.new(0.895, 0.046, 0, 0) then
Direction = "Left"
end
if Direction == "Right" then
Banana:TweenPosition(UDim2.new(Banana.Position.X.Scale + 0.005, 0, 0, 0), "Out", "Sine", 1)
elseif Direction == "Left" then
Banana:TweenPosition(UDim2.new(Banana.Position.X.Scale - 0.005, 0, 0, 0), "Out", "Sine", 1)
end
end
wait(0.01)
end
From looking at it, you probably don’t have enough parameters put in for the UDim2s. UDim2.new(xScale, xOffset, yScale, yOffset) and you only have 3 numbers.
You are also comparing the Banana’s Position which is a UDim2, with a Vector2.
local CD = script.Parent.ClickDetector
local ScreenGUI = game.Players.LocalPlayer.PlayerGui.ScreenGui
local Banana = ScreenGUI.MainFrame.WorkFrame.Banana
local Direction = "Right"
CD.MouseClick:Connect(function()
ScreenGUI.Enabled = true
end)
while true do
if ScreenGUI.Enabled == true then
if Banana.Position == UDim2.new(0, 0.046, 0, 0) then
Direction = "Right"
elseif Banana.Position == UDim2.new(1, -0.046, 0, 0) then
Direction = "Left"
end
if Direction == "Right" then
Banana:TweenPosition(UDim2.new(Banana.Position.X.Scale + 0.005, 0, 0, 0), "Out", "Sine", 1)
elseif Direction == "Left" then
Banana:TweenPosition(UDim2.new(Banana.Position.X.Scale - 0.005, 0, 0, 0), "Out", "Sine", 1)
end
end
wait(0.01)
end
I used this and made a few changes but there is still an issue, sometimes it goes the wrong way and ends up going off the screen. If you want a video I can provide one but it takes a bit o if you can see an error here and fix it without the video it would save lots of time.
local ScreenGUI = script.Parent.Parent.Parent.Parent
local Banana = script.Parent
local Direction = "Right"
local Computor = game.Workspace.Computor
local Screen = Computor:WaitForChild("Screen")
local CD = Screen.ClickDetector
CD.MouseClick:Connect(function()
ScreenGUI.Enabled = true
end)
while true do
if ScreenGUI.Enabled == true then
if Direction == "Right" then
Direction = "Left"
Banana:TweenPosition(UDim2.new(Banana.Position.X.Scale + 0.895, 0, 0, 0), "Out", "Sine", 1)
elseif Direction == "Left" then
Direction = "Right"
Banana:TweenPosition(UDim2.new(Banana.Position.X.Scale - 0.895, 0, 0, 0), "Out", "Sine", 1)
end
end
wait(0.01)
end
If you can provide videos of the issues, always do so. It will help with getting a response faster.
Although i might’ve been able to fix it for you. Did you try adding a screenWidth with AbsoluteSize?
If you haven’t tried that yet, you could try this code, Let me know if it works!
local ScreenGUI = script.Parent.Parent.Parent.Parent
local Banana = script.Parent
local Direction = "Right"
local Computor = game.Workspace.Computor
local Screen = Computor:WaitForChild("Screen")
local CD = Screen.ClickDetector
local screenWidth = Screen.AbsoluteSize.X
local bananaWidth = Banana.Size.X.Offset
local step = bananaWidth / screenWidth
CD.MouseClick:Connect(function()
ScreenGUI.Enabled = true
end)
while true do
if ScreenGUI.Enabled then
if Direction == "Right" and Banana.Position.X.Offset < screenWidth - bananaWidth then
Direction = "Left"
Banana:TweenPosition(UDim2.new(0, Banana.Position.X.Offset + step, 0, 0), "Out", "Sine", 1)
elseif Direction == "Left" and Banana.Position.X.Offset > 0 then
Direction = "Right"
Banana:TweenPosition(UDim2.new(0, Banana.Position.X.Offset - step, 0, 0), "Out", "Sine", 1)
end
end
wait(0.01)
end
Oh i see, Try this code instead then, it might work if i understand your issue correctly.
Once again though, a video would be nice to have.
local ScreenGUI = script.Parent.Parent.Parent.Parent
local Banana = script.Parent
local Direction = "Right"
local Computor = game.Workspace.Computor
local Screen = Computor:WaitForChild("Screen")
local CD = Screen.ClickDetector
local screenLeftBound = Screen.Position.X.Offset
local screenRightBound = screenLeftBound + Screen.Size.X.Offset
local bananaWidth = Banana.Size.X.Offset
local step = bananaWidth / (screenRightBound - screenLeftBound)
CD.MouseClick:Connect(function()
ScreenGUI.Enabled = true
end)
while true do
if ScreenGUI.Enabled then
if Direction == "Right" and Banana.Position.X.Offset + bananaWidth < screenRightBound then
Direction = "Left"
Banana:TweenPosition(UDim2.new(0, Banana.Position.X.Offset + step, 0, 0), "Out", "Sine", 1)
elseif Direction == "Left" and Banana.Position.X.Offset > screenLeftBound then
Direction = "Right"
Banana:TweenPosition(UDim2.new(0, Banana.Position.X.Offset - step, 0, 0), "Out", "Sine", 1)
end
end
wait(0.01)
end