Hello! I am trying to make a gui for a fishing system, where it is not just ‘click when the bait makes bubbles from within the water’ type of thing.
I want to achieve something like this:
My code is something like this, (and yes I know that the error says ‘Udim expected, got a number’, but I just don’t know how to implement that):
local button = script.Parent
--local count = 1
local image = button.Parent.ImageLabel
local count = 0
button.Activated:Connect(function()
count+= 1
if count == 1 then
image:TweenSize(
UDim2.new(0, 89,0, 0),
Enum.EasingDirection.Out,
Enum.EasingStyle.Linear,
10)
end
local height = image.Size.Height
--image.Size = UDim2.new(image.Size.X.Scale, image.Size.X.Offset, height+10, image.Size.Y.Offset)
image.Size.Y+=10
end)
The tweening works fine, the height increment doesn’t. I do know that the error says ‘Udim expected, got a number’, but I just don’t know how to implement that.
The idea is that the image label will start from somewhere in the middle, get pulled down by the tween, but pulled up by mouse clicks from the button. (If the image label reaches its y axis height of zero, the ui destroys itself and the fish is not caught, but if it reaches its max height, the fish is caught, but I will code this later on.)
Thanks for you time!
Tween while running override whatever you set so you have to add movement manually via looping and makes it lerp for smooth movement. So height is whatever tween is moving at.
The reason it says Udim expected, got a number is because image.Size.Y is Udim and Udim can’t do math operation with raw number or integar so you have to add Udim with Udim. Though I recommend changing Size by using Udim2.
Check GuiObject documentation for valid properties.
Edit: You can just do another tween to override the current tween.
Yoohoo! Thanks for your advice!
It’s working fine now. What I did was ditching the tween service entirely, and replaced it with a for loop, because I atleast could NOT override that thing. Another thing is, instead of changing the size, i changed the position, it apparently made it easier. Heres the code and the output:
local button = script.Parent
local image = button.Parent.ImageLabel
local count = 0
local load = script.Parent.Parent:WaitForChild("ImageLabel")
button.Activated:Connect(function()
count+= 1
local height = image.Size.Height
if count == 1 then --> for initiating the bar's movement, ONLY in the first click
for i = 10, 1, 0 do
image.Position = image.Position + UDim2.new(0,0,0.02,0) -->increases the bar's y value over time,uses Y's SCALE value ,
task.wait(0.1) --> a bypassing of tween, this can be changed depending upon rarity of fish(same applies to above value change)
if image.Position.Y.Scale <= UDim2.new(0.03, 0,0.133, 0).Y.Scale then --> if top limit is reached, fish is caught, ui destroys
print("Fish caught! WOOHOO")
print(image.Position.Y.Scale)
script.Parent.Parent:Destroy()
else if image.Position.Y.Scale>= UDim2.new(0.03, 0,0.948, 0).Y.Scale then --> if bottom limit is reached, fish is not caught, ui destroys
print("Fish not caught :( ")
print(image.Position.Y.Scale)
script.Parent.Parent:Destroy()
end
end
end
else
image.Position = image.Position + UDim2.new(0,0,-0.045,0) -->increases the bar's y value every click,uses Y's SCALE value
end
end)
TweenSize and TweenPosition is deprecated and override is false by default so you can’t override tween with another tween(by default). So in the future when you use tween use TweenService by it Create method.