Im trying to make a gun but whenever another player is moving it for some reason does not work? There are no errors btw. You can see in the output log that it is not printing “as” as when it prints it, it touches something.
Here is the bullet script:
local Bullet = script.Parent
local NearbyBulletSound = Bullet:WaitForChild('NearbyBulletSound')
local Players = game:GetService("Players")
Debris = game:GetService("Debris")
local Damage = Bullet:WaitForChild("Damage")
local Damaged = false
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
Bullet.Touched:Connect(function(hit)
print("as")
local CharHum = hit.Parent.Humanoid
if hit and CharHum and CharHum.Health > 0 and Damaged == false then
local player = game.Players:GetPlayerByUserId(Bullet.Owner.Value)
local hrp = player.Character:FindFirstChild("HumanoidRootPart")
Bullet.Size += Vector3.new(player.Character.HumanoidRootPart.CFrame.LookVector)
CharHum.Health = CharHum.Health - Damage.Value
Damaged = true
if CharHum.Health == 0 then
player.folder.lastkilled.Value = hit.Parent.Name
game.ReplicatedStorage.Killed:FireClient(player)
NearbyBulletSound:Play()
UntagHumanoid(CharHum)
player.folder.killstreak.Value += 1
TagHumanoid(CharHum, player)
end
task.wait(1)
Damaged = false
end
wait(0.3)
Bullet:Destroy()
end)
while wait(0.4) do
Bullet:Destroy()
end