My goal for these lines of code is when it reaches a certain size, the button destroys. I spent 3 hours on this yesterday not knowing why it wouldn’t work. I’m having trouble is where the If statements are. Any suggestions or fixes, even another method? Thanks.!
Make sure this is a server script, if it’s localized then try performing this action on the server, using an event.
You can fix this by determing X,Y and Z.
if Vector3(game.Workspace.WaterHeightScript.Water.Size.X,game.Workspace.WaterHeightScript.Water.Size.Y,game.Workspace.WaterHeightScript.Water.Size.Z) == Vector3(4,2.4,2) then
Instead of just calling the size of it.
When I test it, this error pops up in the output [14:58:37.763 - Workspace.WaterHeightScript.Clicker.Script:4: attempt to call global ‘Vector3’ (a table value)]
You’re on the right track. Your code completely works, it’s just the way in which you’re checking this is not exactly the best (neither is your set up). What you’re going to want to do instead is check the Y coordinate of the position to determine if it’s reached an appropriate height.
-- Use variables to avoid redundancy!
local system = workspace.WaterHeightScript
local water = system.Water
local function grow()
-- Everything here we keep the same except make it easier for ourselves by doing the addition before
-- You will see why this is a good choice
local newY = water.Size.Y + 2
water.Size = Vector3.new(4, newY, 4)
-- Now check if the new Y is high enough (not exactly, remember floating point inaccuracies exist)
if newY >= 2.4 then
-- Sure you didn't mean ClickDetector?
system.Clicker:Destroy()
end
end)
script.Parent.ClickDetector.MouseClick:Connect(grow)
We do the addition first instead of in the new Vector creation so that we can use that Y value for our if statement. Next, instead of checking for exacts which it may never be, we instead check if the new Y size is greater than or equal to 2.4; this will also catch floating point inaccuracies. And with that, you got your item.
An alternate way would be to check the Y coordinate of the Size in the if statement as opposed to creating a new Vector3 and checking if the current size is equal to it, but since we already have the Y in a variable there’s no need for us to go out of our way and unnecessarily construct objects.
What if you just remove vector3?
if (game.Workspace.WaterHeightScript.Water.Size.X,game.Workspace.WaterHeightScript.Water.Size.Y,game.Workspace.WaterHeightScript.Water.Size.Z) == (4,2.4,2) then
Okay, thanks! I’m still a noobie at scripting, tysm.