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)
2 Likes
try this out:
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
2 Likes
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.
1 Like
“CD” is connected to a part not the screengui
1 Like
Are you meaning to use a ClickDetector inside the part? MouseClick
doesn’t exist on BaseParts.
1 Like
Oh alright, this is the edited one
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
1 Like
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
1 Like
Yes, if you can see an error in my recent reply please let me know
1 Like
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
The “Screen” is a part that you click to open the gui. Not the gui itself
1 Like
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
1 Like
For
local screenLeftBound = Screen.Position.X.Offset
It says you "attempt to index nil with offset.
Also, I would send a video but it just does nothing with this new script so there is not much to show.
1 Like
you can at least present what you want to achieve
hold up i recognize you from scripting helpers
1 Like
How am I supposed to present this? Also I remember u too
1 Like
for example, drawing what you want to see in the screen and the expected result
I think I will just try a different approach to a “work” system. Thanks so much for the help guys!