So I'm trying to make something where a bunch of air particle meshes do damage, and the touched event seems to be working and everything, but only when I put it before the part that moves the meshes. Whenever I do this, it makes the mesh parts always appear on top of anything in their way.
What Happens: https://gyazo.com/b2760b051b4c407e5b229e4bf19ac3a9
Server Script:
-- Replicated Storage
local repStorage = game:GetService("ReplicatedStorage")
local airEvents = repStorage:WaitForChild("Powers"):WaitForChild("Air")
local mainEvent = airEvents:WaitForChild("Main")
local function setY(part,otherPart)
local yToSet = otherPart.CFrame.Y
local xToSet = part.CFrame.X
local zToSet = part.CFrame.Z
part.Position = Vector3.new(xToSet,yToSet,zToSet)
end
-- Event
mainEvent.OnServerEvent:Connect(function(player,key,mouseCFrame)
-- Character Stuff
local char = game.Workspace[player.Name]
local humanoid = char.Humanoid
local rootPart = char.HumanoidRootPart
-- Getting Meshes
local airBall = script.AirBall
local airLaunch = script.AirLaunch
local ring = script.Ring
local tornadoPunch = script.TornadoPunch
local airParticle = script.AirParticle
-- Power Stuff
local stats = player.Stats
local power = stats:WaitForChild("Power")
local powerLevel = power.PowerLevel
if mouseCFrame ~= nil then
if key == Enum.KeyCode.R then
wait(1.75)
local uno = airLaunch:Clone()
local dos = airLaunch:Clone()
uno.Parent = game.Workspace
dos.Parent = game.Workspace
dos.Orientation = Vector3.new(180,0,0)
uno.Orientation = Vector3.new(0,0,0)
uno.Size = Vector3.new(30,10,30)
dos.Size = Vector3.new(60,20,60)
local counter = 0
for i,v in pairs(game.Workspace:GetChildren()) do -- Here's the damage part.
if v.Name == "AirLaunch" and v.ClassName == "MeshPart" then
local db = false
v.Touched:Connect(function(hit)
local otherHumanoid = hit.Parent.Humanoid
if otherHumanoid ~= nil then
if hit.Parent.Name ~= player.Name and db == false and hit.Parent.ClassName == "Model" then
otherHumanoid:TakeDamage((powerLevel.Value*0.05)*math.random(5,15))
db = true
wait(5)
db = false
end
end
end)
end
end
while wait(0.01) do
if counter < 10 then
uno.Orientation = uno.Orientation + Vector3.new(0,40,0)
dos.Orientation = dos.Orientation + Vector3.new(0,-40,0)
uno.Position = rootPart.CFrame.p -- I made sure to use CFrame.p instead of position, but it still did this.
dos.Position = rootPart.CFrame.p
counter = counter + 0.05
elseif counter >= 10 then
counter = 0
for i = 15,40,5 do
uno.Size = Vector3.new(i,i/3,i)
dos.Size = Vector3.new(i*2,(i/3)*2,i*2)
uno.Transparency = i/40
dos.Transparency = i/40
end
break
end
end
-- When I put the damage here, the meshes work fine, but the damage doesn't.
uno:Destroy()
dos:Destroy()
elseif key == Enum.KeyCode.T then
-- Script goes on, but too long to put it as a question. This is all you will need anyway.
Client Script:
-- Player Stuff
local player = game.Players.LocalPlayer
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
-- Remote Events
local repStorage = game:GetService("ReplicatedStorage")
local airF = repStorage:WaitForChild("Powers"):WaitForChild("Air")
local main = airF:WaitForChild("Main")
local db1 = false
local db2 = false
local db3 = false
local r1AnimCooldown = 0.75
local r2AnimCooldown = 1
local r1Anim = "rbxassetid://2634163875"
local r2Anim = "rbxassetid://2634201637"
local r3Anim = "rbxassetId://2648818924"
local flyCooldown = 10
local launchCooldown = 5
local tornadoCooldown = 30
UIS.InputBegan:Connect(function(key,playerIsTyping)
if playerIsTyping == false then
if key.KeyCode == Enum.KeyCode.R and db1 == false then
local anim1 = Instance.new("Animation")
local anim2 = Instance.new("Animation")
local anim3 = Instance.new("Animation")
anim1.AnimationId = r1Anim
anim2.AnimationId = r2Anim
anim3.AnimationId = r3Anim
local Anim1 = humanoid:LoadAnimation(anim1)
local Anim2 = humanoid:LoadAnimation(anim2)
local Anim3 = humanoid:LoadAnimation(anim3)
Anim1.Priority = Enum.AnimationPriority.Action
Anim2.Priority = Enum.AnimationPriority.Action
Anim3.Priority = Enum.AnimationPriority.Action
db1 = true
main:FireServer(key.KeyCode,mouse.Hit)
Anim1:Play()
wait(r1AnimCooldown)
Anim1:Stop()
Anim2:Play()
wait(r2AnimCooldown)
Anim2:Stop()
Anim3:Play()
wait(flyCooldown)
Anim3:Stop()
db1 = false
-- Again, it goes on, but the rest is just the other moves, and not the thing I'm asking for help on.
