So i have a part named Meteor, and added this script inside it to make it fall and when it hits other parts they disappear. Though it doesn't work, can anyone help me with my problem?
local coolbrick = instance.new("Part", game.Workspace) coolbrick.name = "Meteor") coolbrick.Anchored = False game.Workspace.coolbrick.Touched:connect(functon(poop) poop:Destroy() local boom = Instance.new("Explosion", game.Workspace) boom.Position = poop.Position end)
Let start with the errors.
Line 1:
instance.new
. Instance should be capitalized.
--The correct syntax should be, Instance.new.
Line2:
coolbrick.name = 'Meteor')
. Name should be capitalized, and the parenthesis is unnecessary.
--The correct syntax should be, coolbrick.Name = 'Meteor`.
Line 3:
coolbrick.Anchored = False
. Boolean values, (true and false values ), should be lowercase.
--The correct syntax should be, coolbrick.Anchored = false.
Line 4:
game.Workspace.coolbrick.
. Since the object itself is not named coolbrick, but the variable of it is, you cannot do this. However, you can use game.Workspace.Meteor
since you named the object meteor, or you can do coolbrick.Touched
since you defined coolbrick as a variable.
Line 4: continued
:connect(functon(poop)
. Function is misspelled.
--The correct syntax should be, :connect(function(poop)
Line 5:
poop:Destroy()
. I would run an if-statement before you delete anything, so that you aren't deleting the baseplate or anything. Also, you should put this a few lines down, so that you can still get the position for the explosion
A few notes:
Lua is a case-sensitive language, meaning you have to be careful when it comes to capitals and lowercasing.
For instance, you had instance
, when Lua only reads Instance
. This would cause an error. Samething with False
.
If you have a variable already defined, you don't need to find the part you defined in workspace. Simply use the variable.
Scripting Time:
local coolbrick = Instance.new('Part', game.Workspace) --Defines coolbrick coolbrick.Name = 'Meteor' --Names coolbrick coolbrick.Anchored = false --Anchors coolbrick coolbrick.Touched:connect(function(poop) --Checks for if it gets touched if poop.Name ~= 'Baseplate' and poop ~= nil then --If the part is not Baseplate and is real local boom = Instance.new('Explosion', game.Workspace) --Explosion creation boom.Position = poop.Position --Explosion position poop:Destroy() --Part destroy end end)
If this helped you, don't forget to accept my answer.