How would i make this script?

ive done something like this but it doesn’t seem to work.

local Max_Number = 25
local Min_Number = 5

local Random = math.random(Min_Number, Max_Number)

wait(Random)

local Parts = game.Workspace.Floor1:GetChildren()
	workspace.Floor1 = false
wait(4)
	script.Parent:Destroy()
end

EDIT SORRY: I need to make a script that unanchors the parts within a model then deletes them after a certain amount of time)

Elaborate on what this script is meant to accomplish?

sorry my bad i forgot to add that I have updated it

This would error because Floor1 is not a property of workspace. What are you trying to do to Floor1?

so im trying to unanchor the model then delete after a certain amount of time

Try this maybe?

local model = script.Parent -- Set script inside of Model or specify the location of model.

local min = 5
local max = 25
local RANDOM = math.random(min, max)

-- Unanchor the parts within the model
for _, part in ipairs(model:GetChildren()) do
	if part:IsA("BasePart") then
		part.Anchored = false
	end
end

-- Wait for the specified amount of time
wait(RANDOM)

-- Delete the parts within the model
for _, part in ipairs(model:GetChildren()) do
	if part:IsA("BasePart") then
		part:Destroy()
	end
end

ohhhh :person_facepalming: right ive changed that now but it still doesn’t change much

local Max_Number = 25
local Min_Number = 5

task.wait(math.random(Min_Number,Max_Number)) -- use task.wait() instead of wait(), you also don't really need a variable

local Parts = workspace.Floor1:GetChildren()

for i, v in Parts do
    if v:IsA("BasePart") then v.Anchored = false end
end

task.wait(4)

script.Parent:Destroy()
1 Like

Im assuming that Floor1 is a model, then why are you setting it to false randomly? If you want to unanchor everything in the model, you loop through each part inside of it like this:

for index, object in ipairs(workspace.Floor1:GetChildren()) do
     -- check if the current iteration is a BasePart, which is basically all types of parts
     if object:IsA("BasePart") then
        object.Anchored = false -- unanchor part
    end
end

Sorry for bad formatting im on mobile

1 Like

this worked thank you! very much

1 Like

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