Hey, i am trying to make a move that reflect body velocity but the move freezes the other moves when it comes into contact. Here is the reflect script >
function MirrorWater(hit) if BodyVelocity > 0 then BodyVelociy.velocity = -BodyVelocity.velocity end end script.Parent.Touched:connect(MirrorWater)
Here is one of the moves I want it to reflect, I think it's because it can't detect the meshes?
bin = script.Parent me = script.Parent.Parent.Parent name = "Lightning God's Charged Particle Cannon" Colour = BrickColor.new("New Yeller") enabled = true cost = 80 Backpack = bin.Parent Player1 = Backpack.Parent Player = Player1.Character LeftShoulder = Player.Torso["Left Shoulder"] RightShoulder = Player.Torso["Right Shoulder"] Run = game:GetService("RunService") na = bin.Name Axe = script.Parent.Parent.Parent.PlayerGui:findFirstChild("Energy") mag = Axe.Magic magmax = Axe.MagicMax game.Debris:AddItem(MagicSym,1) x = Instance.new("Part") x.BrickColor = Colour x.Size = Vector3.new(10,10,40) x.TopSurface = "Smooth" x.BottomSurface = "Smooth" x.Shape = "Block" x.Name = "DS" x.CanCollide = false x.Anchored = false p = script.PointLight:clone() p.Parent = x fd = script.Firedamage:clone() fd.Parent = x o = Instance.new("StringValue",x) o.Value = me.Name o.Name = "Owner" z = Instance.new("SpecialMesh",x) z.MeshType = "Sphere" z.Scale = Vector3.new(0,0,0) y = Instance.new("BodyVelocity") y.maxForce = Vector3.new(math.huge, math.huge, math.huge) y.velocity = me.Character.Torso.CFrame.lookVector* 330 x.Parent = Workspace y.Parent = x x.CFrame = me.Character.Torso.CFrame*CFrame.new(0,0,-3) * CFrame.Angles(0,0,0) fd.Disabled = false x.Transparency = .2 x2 = x:clone() x2.BrickColor = BrickColor.new("Really black") x2.Size = x.Size * Vector3.new(1.25,1.25,1.25) x2.CanCollide = false x2.Position = x.Position x2.Parent = Workspace z2 = x2["Mesh"] x2["Firedamage"]:remove() fd2 = script.Firedamage2:clone() fd2.Parent = x2 fd2.Disabled = false x2.Transparency = x.Transparency * 3 w1 = Instance.new("Weld", x) w1.Part0 = x2 w1.Part1 = x w1.C1 = CFrame.fromEulerAnglesXYZ(0, 0, 0) *CFrame.new(0 ,0, 0) game.Debris:AddItem(x,3) game.Debris:AddItem(x2,3) for i = 1,5 do z.Scale = z.Scale + Vector3.new(.2,.2,.2) x.Transparency = x.Transparency - .02 z2.Scale = z2.Scale + Vector3.new(.2,.2,.2) x2.Transparency = x2.Transparency - .02 wait(.005) end enabled = true function onS(mouse) mouse.Button1Down:connect(function() onButton1Down(mouse) end) end bin.Selected:connect(onS)
Removed some of the un needed stuff
The following line is wrong:
if BodyVelocity > 0 then
BodyVelocity
is (presumably) an object -- it isn't "larger" than anything.
I'm assuming you meant this to only make it reflect if it's moving into the object. This requires a bit more assumptions that you haven't stated, so I'm not going to address that rigorously, and instead address a simpler solution.
In addition, you didn't define BodyVelocity
. I'm assuming that it would be something like this:
function MirrorWater(hit) local BodyVelocity = hit:FindFirstChild("BodyVelocity") if BodyVelocity then BodyVelocity.velocity = -BodyVelocity.velocity end end
We should make sure we only reflect it once (which is simpler than the vector math to determine if it's coming at you, though we could do that too). A simple way would be to insert another object into the part saying it's been reflected (assuming the part is cleaned up rather than reused in the future)
function MirrorWater(hit) local BodyVelocity = hit:FindFirstChild("BodyVelocity") if not hit:FindFirstChild("AlreadyMirrored") then if BodyVelocity then BodyVelocity.velocity = -BodyVelocity.velocity Instance.new(hit, "NumberValue").Name = "AlreadyMirrored" end end end
Touched
events will not fire when they contact the mesh -- only when they contact the part itself. Size (and/or Shape into a Ball) the object appropriately to match its mesh.