I just wanna know if this code is efficient. Basically for a fishing game, simple UI, where a frame moves to the left, and as you click it moves to the right. Idea is frame should be somewhat sporadic in its movements. If it goes too far to the left, you fail, if it goes too far to the right (too much clicking) you fail
This first chunk is what moves the fish to the left.
-- Repeat until fish caught or fail
while not FishCaught do
-- Get random amount to move fish
local RandomMove = math.random(1, 5) / 100 -- Between 0.01 - 0.05
Position = Position - RandomMove
-- Move fish
local RandomTime = math.random(10, 20) / 100 -- Between 0.1 - 0.2
local FishTween = TweenService:Create(BottomFish, TweenInfo.new(RandomTime), {Position = UDim2.new(Position, 0, 0.5, 0)})
FishTween:Play()
FishTween.Completed:Wait()
end
And when you click
local function InputBegan(input, GPE)
if GPE then return end
-- Only fire for mouse click or touch
if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end
if Total > 70 then return end
Position = Position + 0.05
Total = Total + 2.5
if Total >= 70 then
if FishCaught then return end
FishCaught = true
end
end
UserInputService.InputBegan:Connect(InputBegan)
And so ‘Position’ is a variable used in both these. It’s a constant across both.
And this is the final result is this
So when I click it moves right, if I leave it, it moves to the left