I would like to have the octagon fall and then respawn, but for some reason it only works once. I thought it was a name issue but the name of the cloned octagon is the same as the previous octagon. I then thought it was because the previous octagon wasn’t getting deleted when it fell past the world border, but in the explorer it seems to have been deleted. I tried allot of stuff. One of the things I tried was to put the if, then statement above the touch event. It doesn’t work. Also the while loop is constantly running so that isn’t the problem either.
Here is a video of the problem:
Here is My code:
local Octogon4 = game.Workspace.Obbies.Obby1.Floatingblocka.Octogon4
local object2 = game.ServerStorage.Octogon2
--##########--
--define a function
local function respawn()
print('mmmm yummmm')
object2:Clone()
object2.Parent = game.Workspace.Obbies.Obby1.Floatingblocka
object2.Position = Vector3.new(-34.171, -13.5, 733.172)
object2.Name = 'Octogon4'
print('gummy bear')
end
local function epic()
print('fall act')
wait(1)
Octogon4.Anchored = false
Octogon4.CanCollide = false
end
--##########--
while true do
wait(0.5)
--$--
local object = game.Workspace.Obbies.Obby1.Floatingblocka:FindFirstChild('Octogon4')
Octogon4.Touched:Connect(epic)
--$--
if object == nil then
respawn()
end
--$--
print('ran')
end
print('Script epi8c')
You are creating a new instance of object2 and setting its parent and position every time the respawn function is called, but you are not actually changing the value of Octogon4 . Octogon4 is still pointing to the original instance of the octagon, so it will not be affected by the changes you make to object2 .
To fix this issue, you can simply assign the result of object2:Clone() to Octogon4 instead of creating a new variable called object2 :
local function respawn()
print('mmmm yummmm')
Octogon4 = object2:Clone()
Octogon4.Parent = game.Workspace.Obbies.Obby1.Floatingblocka
Octogon4.Position = Vector3.new(-34.171, -13.5, 733.172)
Octogon4.Name = 'Octogon4'
print('gummy bear')
end
Alternatively, you can update the value of object2 to point to the new instance of the octagon:
local function respawn()
print('mmmm yummmm')
object2 = object2:Clone()
object2.Parent = game.Workspace.Obbies.Obby1.Floatingblocka
object2.Position = Vector3.new(-34.171, -13.5, 733.172)
object2.Name = 'Octogon4'
print('gummy bear')
end
Either way, this should allow the octagon to respawn and fall indefinitely.
I tried it, it doesn’t work. The problem seems to be the touch event doesn’t recognize the second Octagon. I thought I solved the value of it by changing the name to it. For some reason what you told me to do doesn’t work. So what you said is true but it doesn’t work for some reason.
The problem is that you are setting the object to nil, but not disconnecting the touch event. This means that the code inside the event is never running, so the object is never removed. Instead, you should disconnect the touch event when the object is removed. This can be done by calling the disconnect() function on the event. local Octogon4 = game.Workspace.Obbies.Obby1.Floatingblocka.Octogon4
local object2 = game.ServerStorage.Octogon2
local connection = nil
–##########–
–define a function
local function respawn()
print(‘mmmm yummmm’)
object2:Clone()
object2.Parent = game.Workspace.Obbies.Obby1.Floatingblocka
object2.Position = Vector3.new(-34.171, -13.5, 733.172)
object2.Name = ‘Octogon4’
print(‘gummy bear’)
end
local function epic()
print(‘fall act’)
wait(1)
Octogon4.Anchored = false
Octogon4.CanCollide = false
end
–##########–
while true do
wait(0.5)
--$--
local object = game.Workspace.Obbies.Obby1.Floatingblocka:FindFirstChild('Octogon4')
if connection == nil then
connection = Octogon4.Touched:Connect(epic)
end
--$--
if object == nil then
respawn()
connection:Disconnect()
connection = nil
end
--$--
print('ran')