Code issues - Model is not getting destroyed

Hello! Does anyone know why my keyModel is not being destroyed in my code? what’s wrong? :frowning:

image

-- Get references to frame and key ProximityPrompts
local frameModel = script.Parent.Parent.Frame
local keyModel = script.Parent.Parent.Key
local keyProximityPrompt = keyModel.keyModelBase:WaitForChild("keyProximityPrompt")

-- Get reference to the frame ProximityPrompt trigger
local frameTriggered = frameModel.basePart:WaitForChild("frameProximityPrompt")

-- Connect the function to the frame ProximityPrompt activation
frameTriggered.Triggered:Connect(function()
	print("Frame ProximityPrompt Triggered")

	-- Wait for a short time before destroying the frame
	wait(0.2)
	frameModel:Destroy()

	-- Wait for an additional time before enabling the key ProximityPrompt
	task.wait(0.5)
	keyProximityPrompt.Enabled = true
end)

task.wait(.2)

-- Connect the function to the key ProximityPrompt activation
keyProximityPrompt.Triggered:Connect(function()
	print("Key ProximityPrompt Activated")

	-- Wait for a short time before destroying the key model
	wait(0.5)
	keyModel:Destroy()
end)
2 Likes

Where is this script located???

2 Likes

this is a server script inside the Frame model

image

2 Likes

So when you destroy the frame model it would destroy the script? You could try to move the script.

4 Likes

Oh I understand! I’ll try it now

1 Like

but there is a problem hmm how could I know if the frame model has been destroyed? since the key will be under this

What if you just placed the script in the key model since that one’s the last one to get destroyed?

2 Likes

Hahaha I hadn’t thought about it but it worked… jesus my brain lol… thank you very much! :smiley:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.