Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How To Make A Random Part Destroy?

Here Is My Code

local SMLPart = game.Workspace.Parts.SMLPart
local LRGPart = game.Workspace.Parts.LRGPart
local Part = {"SMLPart", "LRGPart"}
local Hint = Instance.new("Hint")
local Random = Part[math.random(#Part)]
wait ()
Hint.Text = Random.. "Has Been Chosen"
Random:Destroy()

The Hint Is Not Showing And This Is The Error;

attempt to call method 'Destroy' (a nil value)

2 answers

✓ Accepted answer

That is because you haven't set any objects in the table, but merely Strings. To fix this, just remove the quotation marks:

local SMLPart = game.Workspace.Parts.SMLPart
local LRGPart = game.Workspace.Parts.LRGPart
local Part = {SMLPart,LRGPart}
local Hint = Instance.new("Hint",workspace)
local Random = Part[math.random(#Part)]
Hint.Text = Random.Name .. "Has Been Chosen"
Random:Destroy()

If any other question is lingering in your mind, don't hesitate to comment!

Accept this question if this helped you, so others can know that it can assist them too.

2 comments

0

thanks this helped so much

0

Can you hit the 'Solved' button if this answers your issue :)

Just remove the quotations and Add how many Parts you want to destroy:

local SMLPart = game.Workspace.Parts.SMLPart
local LRGPart = game.Workspace.Parts.LRGPart
local Part = {SMLPart,LRGPart}--remove quotations because it is a Variable
local Hint = Instance.new("Hint",workspace)
local Random = Part[math.random(1 ,#Part)]--How many parts you want to pick randomly
Hint.Text = Random.Name .. "Has Been Chosen"
Random:Destroy()

if this Helped please **Upvote **and Accept Answer!

2 comments

2

No need for the '1' in front. math.random uses 1 as a default if not provided.

0

Oh thanks bro!

This discussion is preserved as it was. New answers, comments, and votes are closed.