So, im making a gun system like Isle game, and it works like this: when u click on a enemy u start aiming at it, then after a certain amount of seconds and the enemy is still in range (not behind a wall or something) it shoots, but the system i made is a little bad, even when the enemy is in range it doesnt shoots, could anyone help me?
The Script
local tool = script.Parent
local remote = tool:WaitForChild("OnShoot")
local shoot_part = tool:WaitForChild("FirePart")
local Config = tool.Config
local Damage = Config.Damage.Value
local SFX = tool:WaitForChild("Handle")
local Particle1 = shoot_part:WaitForChild("Muzzle")
local Shooting = false
remote.OnServerEvent:Connect(function(player, target)
if not Shooting and Config.Ammo.Value > 0 and (player.Character.HumanoidRootPart.Position-target.Position).magnitude <= 100 then
Config.Ammo.Value -= 1
Shooting = true
local filter = {player.Character}
for i,v in pairs(workspace:GetDescendants()) do
if v:FindFirstChild("ZombieNoid") then
table.insert(filter, #filter+1, v)
end
end
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = filter
tool.Aim:FireClient(player)
wait(2)
local raycast = workspace:Raycast(shoot_part.Position, (target.Position-player.Character.HumanoidRootPart.Position).unit*1000, params)
if raycast then
tool.Cancel:FireClient(player)
wait(1)
Shooting = false
else
Particle1.Enabled = true
tool.Shoot:FireClient(player)
target.Parent.ZombieNoid:TakeDamage(25)
wait(0.2)
Particle1.Enabled = false
wait(3)
Shooting = false
end
elseif Config.Ammo.Value == 0 then
tool.ThrowNoAmmo:FireClient(player)
end
end)
Can you be a bit more specific about the issue you’re having? Is anything at all happening? Is the tool.Aim event being fired? Etc.
well it aims, and it fires the event but the raycast is bad, when the raycast fires even though there isnt any part in the way it doesnt shoots
also dont mind the fire ThrowNoAmmo its a festure that i forgot to remove in this script
ok
i can help tmr
15h later
ok!
post must be at least 30 letters
i can help you get rid of that
Select this:
ohh thx
oh nvm i found out a fix that also made the script a lot smaller! but thx!
Please use task.wait(x)
not wait(x)
. The people at roblox encourage you to use task.wait(x)
instead of just wait(x)
. You can look at why it’s better here: Task Library - Now Available!