Hello, so I’m having three problems with this script
The explosion won’t explode unless it hits the ground but won’t if it hits a player/dummy
The ammo gui doesn’t change to the current ammo
I don’t want the player to die to their own rocket I can’t figure out how to fix that though
Client Side
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local debounce = true
local ammo = 3
local ammogui = game.StarterGui["Ammo and Elims"].Ammo
tool.Activated:Connect(function()
if ammo ~= 0 then
local humanoid = tool.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and debounce == true then
debounce = false
local position = mouse.Hit.Position
tool["Create Rocket"]:FireServer(position)
ammo = ammo - 1
task.wait(2)
debounce = true
if ammo == 0 then
ammogui.Text = "Reloading"
wait(3)
ammo = 3
ammogui.Text = ammo
end
end
end
end)
Server Side
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
tool["Create Rocket"].OnServerEvent:Connect(function(player, position)
local rocket = Instance.new("Part")
rocket.Parent = workspace
rocket.CFrame = CFrame.new(handle.Position + Vector3.new(0, 1, 0), position)
rocket.Size = Vector3.new(1, 1, 2)
rocket.BrickColor = BrickColor.new("Really red")
local velocity = Instance.new("BodyVelocity")
velocity.Parent = rocket
velocity.Velocity = (position - handle.Position).Unit * 50
velocity.MaxForce = Vector3.new("inf", "inf", "inf")
rocket.Touched:Connect(function(hit)
if hit ~= handle and not tool.Parent:FindFirstChild(hit.Name) then
local explosion = Instance.new("Explosion")
if explosion.Hit == player then
explosion = nil
else
explosion.Parent = workspace
explosion.Position = rocket.Position
rocket:Destroy()
end
end
end)
end)
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local debounce = true
local ammo = 3
local ammogui = player.PlayerGui:WaitForChild("Ammo and Elims").Ammo
tool.Activated:Connect(function()
if ammo ~= 0 then
local humanoid = tool.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and debounce == true then
debounce = false
local position = mouse.Hit.Position
tool["Create Rocket"]:FireServer(position)
ammo -= 1
ammogui.Text = ammo
task.wait(2)
debounce = true
end
end
if ammo == 0 then
ammogui.Text = "Reloading"
task.wait(3)
ammo = 3
ammogui.Text = ammo
end
end)
Explosion.Hit is an event, not an Object Value. Issue 3’s solution fixes this.
Issue number 2:
for issue number 2, instead of relying on guis to see how much ammo the launcher has, i would use a bool value instead, subtract the value on the server and then use Instance:GetPropertyChangedSignal to detect when the rocket ammo has changed on the client so that the amount can be displayed.
Issue 3:
Overhaul your explosion system. Instead of using roblox’s default explosion functionality to kill players/npc’s, you can just create your own custom one without having to get rid of the explosion item.
You can simply set the blast radius to 0, then when the explosion happens, loop through everything that is intended to explode and then check its distance with magnitude. This is a commonly used method amongst developers.
If this fixed your problems mark this as a solution.