I am trying to make one kill effect for my gun. The effect works but I only want to clone the effects into the character only when the humanoid dies. This clone if the humanoid is dead or alive.
local effect1 = game.ReplicatedStorage.washbasin
local effect2 = game.ReplicatedStorage.Plate
local effect3 = game.ReplicatedStorage.Plate2
local debounce = false
local bullet = script.Parent
local function player_check(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if humanoid and humanoid.Parent.Name ~= bullet.Attacker.Value then
if humanoid.Died then
debounce = true
local character = humanoid.Parent
local humanoidRoot = character.HumanoidRootPart
local effectClone1 = effect1:Clone()
effectClone1.Parent = character
effectClone1.Position = humanoidRoot.Position
local effectClone2 = effect2:Clone()
effectClone2.Parent = character
effectClone2.Position = humanoidRoot.Position
local effectClone3 = effect3:Clone()
effectClone3.Parent = character
effectClone3.Position = humanoidRoot.Position
print("test")
end
debounce = false
end
end
bullet.Touched:Connect(player_check)
humanoid.Died is an event not a bool property.
You can change it to if humanoid.Health <= 0 then .
Don’t know if this will work 100% cause of the way this is being handled (if you have a separate damage script it would not be in sync that is).
You can yield the block by using the method in the event called :Wait() basically it would pause the current part of the thread until the event fires
Humanoid.Died:Wait()
However I suggest that you Connect the event to a method then have it do what you want
Humanoid.Died:Connect(function()
-- Do what you want here
end)
-- Or
local function OnDied()
-- Do what you want here
end
Humanoid.Died:Connect(OnDied)
-- Both of these ways are the same
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Remote Events
local effect1 = ReplicatedStorage:WaitForChild("washbasin")
local effect2 = ReplicatedStorage:WaitForChild("Plate")
local effect3 = ReplicatedStorage:WaitForChild("Plate2")
local bullet = script.Parent
local debounce = false
function OnDeath(character, humanoid, humRootPart)
humanoid.Died:Connect(function()
if not character.Name == bullet.Attacker.Value then
debounce = true
local effectClone1 = effect1:Clone()
effectClone1.Parent = character
effectClone1.Position = humRootPart.Position
local effectClone2 = effect2:Clone()
effectClone2.Parent = character
effectClone2.Position = humRootPart.Position
local effectClone3 = effect3:Clone()
effectClone3.Parent = character
effectClone3.Position = humRootPart.Position
print("tested")
end
wait()
debounce = false
end)
end
bullet.Touched:Connect(function(hitPart)
if not hitPart.Parent:FindFirstChildWhichIsA("Humanoid") then
return
end
local character = hitPart.Parent
local humanoid = character:WaitForChild("Humanoid")
local humRootPart = character.HumanoidRootPart
OnDeath(character, humanoid, humRootPart)
end)
local RS = game:GetService("ReplicatedStorage")
local Effects = {
RS:WaitForChild("washbasin"),
RS:WaitForChild("Plate"),
RS:WaitForChild("Plate2")
}
local debounce = false
local bullet = script.Parent
local function player_check(otherPart)
if not otherPart.Parent:FindFirstChild("Humanoid") then return end
local humanoid = otherPart.Parent.Humanoid
local character = humanoid.Parent
local humanoidRoot = character.HumanoidRootPart
if humanoid.Parent.Name ~= bullet.Attacker.Value then
if humanoid.Health <= 0 then
debounce = true
for i = 1, #Effects do
local EffClone = Effects[i]:Clone()
EffClone.Parent = character
EffClone.Position = humanoidRoot.Position
print(Effects[i].Name)
end
end
debounce = false
end
end
bullet.Touched:Connect(player_check)
“Workspace.Bullet.KillEffect:28: Ambiguous syntax: this looks like an argument list for a function call, but could also be a start of new statement”
Nvm fixed you tried to print and you said (“tested”) without print()
local bullet = script.Parent
local effect1 = game.ReplicatedStorage.washbasin
local effect2 = game.ReplicatedStorage.Plate
local effect3 = game.ReplicatedStorage.Plate2
local debounce = false
bullet.Touched:Connect(function(otherHumanoid)
if otherHumanoid.Parent:FindFirstChild("Humanoid") and otherHumanoid.Parent.Humanoid.Health <= 0 then
debounce = true
local character = otherHumanoid.Parent
local humanoid = character.Humanoid
local humanoidRoot = character.HumanoidRootPart
humanoid.Died:Connect(function()
local effectClone1 = effect1:Clone()
effectClone1.Parent = character
effectClone1.Position = humanoidRoot.Position
local effectClone2 = effect2:Clone()
effectClone2.Parent = character
effectClone2.Position = humanoidRoot.Position
local effectClone3 = effect3:Clone()
effectClone3.Parent = character
effectClone3.Position = humanoidRoot.Position
print("test")
end)
end
wait()
debounce = false
end)
I have 2 scripts inside the bullet maybe that can be my issue
local bullet = script.Parent
local function player_check(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if humanoid and humanoid.Parent.Name ~= bullet.Attacker.Value then
if otherPart.Name == "Head" then
humanoid:TakeDamage(100)
bullet:Destroy()
else
humanoid:TakeDamage(50)
bullet:Destroy()
end
end
end
bullet.Touched:Connect(player_check)
game.Debris:AddItem(bullet, 10)