Hi, i have this code who fires a sphere projectile, it works well with players but the touch event not firing when it touch a wall or object, any idea why ?
local module = require(game.ReplicatedStorage.Modules.CombatModule)
local RS = game:GetService("ReplicatedStorage")
local RNS = game:GetService("RunService")
local throw_re = RS:WaitForChild("MetalBallRE")
local projectile_template = RS:WaitForChild("MetalBall")
local distance = 50
local speed = 1
local velocity = speed * 60
local lifetime = distance / velocity
local damageDebounce = false
local function applyDamage(hit, projectile, character)
if hit:IsDescendantOf(character) then
return
end
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local alive = module.isAlive(humanoid)
if humanoid and alive and not damageDebounce then
damageDebounce = true
local player = game.Players:GetPlayerFromCharacter(character)
humanoid:TakeDamage(10)
player.leaderstats.Hit.Value += 1
wait()
damageDebounce = false
end
projectile:Destroy()
end
local function throw(player)
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9126003290"
sound.Parent = player.Character
sound.RollOffMode = Enum.RollOffMode.Linear
sound.RollOffMinDistance = 10
sound.RollOffMaxDistance = 1000
sound:Play()
local projectile = projectile_template:Clone()
local character = player.Character
local hrp = character.HumanoidRootPart
projectile.Parent = workspace
projectile.Position = hrp.CFrame.Position + hrp.CFrame.LookVector * 1
projectile.Orientation = Vector3.new(0,hrp.Orientation.Y,0)
projectile.Touched:Connect(function(hit)
print("rrr")
applyDamage(hit, projectile, character)
end)
RNS.Heartbeat:Connect(function()
projectile.Position = projectile.Position + projectile.CFrame.LookVector * 1
end)
game.Debris:AddItem(projectile, lifetime, player)
end
throw_re.OnServerEvent:Connect(throw)