x = Instance.new("Part")
Attack = script.Parent
function onTouched(Part)
if Part:FindFirstChild("Humanoid") == nil then
script.Disabled = true
numberofbricks = math.random(6,15)
for i = 1,numberofbricks do
PartSize = math.random(1,4)
x.Size = Vector3.new(PartSize, PartSize, PartSize)
x.CFrame = Attack.CFrame
x.Parent = game.Workspace
x.BrickColor = Part.BrickColor
x.BottomSurface = "Smooth"
x.TopSurface = "Smooth"
wait()
end
end
end
Attack.Touched:connect(onTouched)
Can someone what error I have on this?
1 answer
So the first thing i noticed is that you are looking for the character's humanoid inside the part, wich is certainly not usefull.
Let's try at your line 6, replace it to:
if Part.Parent:FindFirstChild("Humanoid") ~= nil then
Why ~= nil? Because, i noticed you want it to find player's touch, but every character, is it NPC or Player has a Humanoid. Your script wouldn't work either way.
~= means Isen't
Also i noticed at line 8 you use a math.random function incorrectly, wich is causing the error.
The math.random function works as math.random(Number,OutOf). So basically you were using 6 numbers out of 15, wich automatically errors, because its a number array (numbers = {})
So, let's try the array method. MathRandomNumerOfBricks = {6,7,8,9,10,11,12,13,14,15} That stores every number that could be in math.random(6,15)
We use: MathRandomNumberOfBricks[] to get a stored value from it. math.random(1,#MathRandomNumberOfBricks) inside the [] to get one value from the array.
So our final script will be:
x = Instance.new("Part")
Attack = script.Parent
function onTouched(Part)
if Part.Parent:FindFirstChild("Humanoid") ~= nil then
script.Disabled = true
MathRandomNumerOfBricks = {6,7,8,9,10,11,12,13,14,15}
numberofbricks = MathRandomNumberOfBricks[math.random(1,#MathRandomNumberOfBricks)]
for i = 1,numberofbricks do
PartSize = math.random(1,4)
x.Size = Vector3.new(PartSize, PartSize, PartSize)
x.CFrame = Attack.CFrame
x.Parent = game.Workspace
x.BrickColor = Part.BrickColor
x.BottomSurface = "Smooth"
x.TopSurface = "Smooth"
wait()
end
end
end
Attack.Touched:connect(onTouched)
Hope this works! If not, tell full output. ~marcoantoniosantos3
3 comments
Actually, he did use math.random correctly.
Didn't work :(
'If not, tell full output', please :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Edit your post to address: 1) Use the Lua code formatting button. 2) Tell us what the problem is.
Its saying this; 01:31:19.147 - Script 'Players.Player.Backpack.Testing 1.Testing 1.Terraindamage', Line 23
@Jazzycoolivan15 There's gotta be more than that. You've only located where the error is at in your script (line 23).