I’m trying to make a rhythm sorts game and I’m trying to make it so if the pot is in the hitbox, it gets flung back.
This is my current code
local start = true
local cowbell = script.Parent["Rhythm Heaven Cowbell"]
local rep = game:GetService("ReplicatedStorage")
local localp = game:FindFirstChild("Players").LocalPlayer
local gui1 = script.Parent.Parent.Hitbox
local gui2 = script.Parent.Parent.pot
function collidesWith(gui1, gui2) -----got this from dev fourm thanks to whoever made it
local gui1_topLeft = gui1.AbsoluteSize
local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize
local gui2_topLeft = gui2.AbsolutePosition
local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize
return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y)) --- return their values
end
script.Parent.MouseButton1Click:Connect(function(plr)
if not debounce then
if start == true then
start = false
script.Parent.Parent.TextLabel.Text = "Tap Joe In Time with the rhythm."
cowbell:Play()
wait(1)
cowbell:Play()
wait(1)
cowbell:Play()
wait(0.5)
cowbell:Play()
wait(0.5)
cowbell:Play()
wait(0.5)
cowbell:Play()
script.Parent.Parent.TextLabel.Visible = false
wait(0.5)
script.Parent.Parent.pleasedontban:Play()
else
script.Parent.Whoosh:Play()
script.Parent.Image = "rbxassetid://121803704513390"
wait(0.13)
if collidesWith() then
gui2:TweenPosition(UDim2.new(0.37, 0,0.403, 0), "Linear", "In", 1, false)
end
script.Parent.Image = "rbxassetid://126828287438911"
end
end
end)
Try printing the gui1, gui2 both under where you define them and under the collidesWith() function then see what they print.
print(gui1, gui2)
function collidesWith(gui1, gui2) -----got this from dev fourm thanks to whoever made it
print(gui1, gui2)
local gui1_topLeft = gui1.AbsoluteSize
local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize
local gui2_topLeft = gui2.AbsolutePosition
local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize
return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y)) --- return their values
end
Make sure you are pathing these correctly:
local gui1 = script.Parent.Parent.Hitbox
local gui2 = script.Parent.Parent.pot
Ok, so basically, you already have gui1 and gui2, but when that function is called, you overwrite those names with the function parameters, and since you don’t send any parameters, gui1 and gui2 is nil
local start = true
local cowbell = script.Parent["Rhythm Heaven Cowbell"]
local rep = game:GetService("ReplicatedStorage")
local localp = game:FindFirstChild("Players").LocalPlayer
local gui1 = script.Parent.Parent.Hitbox
local gui2 = script.Parent.Parent.pot
function collidesWith(gui1, gui2) -----got this from dev fourm thanks to whoever made it
local gui1_topLeft = gui1.AbsoluteSize
local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize
local gui2_topLeft = gui2.AbsolutePosition
local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize
return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y)) --- return their values
end
script.Parent.MouseButton1Click:Connect(function(plr)
if not debounce then
if start == true then
start = false
script.Parent.Parent.TextLabel.Text = "Tap Joe In Time with the rhythm."
cowbell:Play()
wait(1)
cowbell:Play()
wait(1)
cowbell:Play()
wait(0.5)
cowbell:Play()
wait(0.5)
cowbell:Play()
wait(0.5)
cowbell:Play()
script.Parent.Parent.TextLabel.Visible = false
wait(0.5)
script.Parent.Parent.pleasedontban:Play()
else
script.Parent.Whoosh:Play()
script.Parent.Image = "rbxassetid://121803704513390"
wait(0.13)
if collidesWith(gui1, gui2) then
gui2:TweenPosition(UDim2.new(0.37, 0,0.403, 0), "Linear", "In", 1, false)
end
script.Parent.Image = "rbxassetid://126828287438911"
end
end
end)
The code is working fine, no errors but I believe it’s due to how I originally coded this section.
There is nothing in the output, can you help me fix it?