I made a grenade launcher, but I don’t want the player to be able to kill himself.
I’m using the explosion system (the debris was before but I keep it in case of a solution).
ServerScript in ServerScriptService :
local debris = game:GetService("Debris")
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(plr, rocketPos, mouseHit)
local explosionPart = Instance.new("Part", workspace)
explosionPart.Anchored = true
explosionPart.CanCollide = false
explosionPart.Transparency = 1
explosionPart.Position = rocketPos
local expoSound = game.ReplicatedStorage.ExplosionSound:Clone()
expoSound.Parent = explosionPart
expoSound:Play()
local explosion = Instance.new("Explosion", workspace)
explosion.Position = explosionPart.Position
debris:AddItem(explosionPart, 3)
end)
And the local script in StarterPlayerScripts :
local debris = game:GetService("Debris")
local explosion = game.ReplicatedStorage.Explosion:Clone()
game.ReplicatedStorage.Fire.OnClientEvent:Connect(function(plr, mouseHit, tool)
local rocket = game.ReplicatedStorage.Rocket:Clone()
rocket.Parent = workspace
rocket.CFrame = CFrame.new(tool.RocketHole.Position, mouseHit)
local bv = Instance.new("BodyVelocity", rocket)
bv.Velocity = CFrame.new(rocket.Position, mouseHit).LookVector * 100
rocket.Touched:Connect(function(hit)
if hit:IsA("BasePart") then
if hit.Parent ~= tool then
rocket:Destroy()
game.ReplicatedStorage.Fire:FireServer(rocket.Position, mouseHit)
end
end
--debris:AddItem(rocket, 3)
local explosionPart = game.ReplicatedStorage.ExplosionPart:Clone()
explosionPart.Parent = workspace
explosionPart.Position = rocket.Position
explosion.Parent = workspace
explosion.Position = rocket.Position
wait(2)
explosionPart:Destroy()
end)
end)
I need to make sure that the player isn’t taking damage from his own explosion.