I’m trying to make a puzzle game where you push a cube onto a button but the button can’t find the cube. It may have something to do with the quotation marks but idk.
Code:
local Button = script.Parent.Button
local Hitbox = script.Parent.Hitbox
local Door = script.Parent.Door
local TweenService = game:GetService("TweenService")
local Room = game.Workspace.Rooms.Room1
while task.wait(0.5) do
local TouchingParts = game.Workspace:GetPartsInPart(Hitbox)
print(TouchingParts)
print(table.find(TouchingParts, "Cube"))
end
Output:
15:25:27.612 ▼ {
[1] = Cube
} - Server - Script:10
15:25:27.617 nil - Server - Script:11
you should save the cube in a variable once it has been found
local cube = Instance -- you should save the cube once the cube has been found
local connection = cube:GetPropertyChangedSignal("Position"):Connect(function()
local touchingparts = workspace:GetPartsInPart(Hitbox)
local cube
for i, v in touchingparts do
if v.Name == "cube" then
cube = v
break
end
end
if cube == nil then
deactivate() -- assuming you have a deactivate function you can deactivate the button if cube is not found
end
end)
-- you can also disconnect this connection once its not needed anymore