Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How To Make A Random Part Destroy?

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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.

0
thanks this helped so much zangdragonoid 0 — 9y
0
Can you hit the 'Solved' button if this answers your issue :) DigitalVeer 1473 — 9y
Ad
Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

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
No need for the '1' in front. math.random uses 1 as a default if not provided. DigitalVeer 1473 — 9y
0
Oh thanks bro! woodengop 1134 — 9y

Answer this question