Hello, I have been working on morphs and a gun system for the last week.
When I tested the guns with a player that had a morph on, the gun did no damage at all.
This is how the morph works when put on the player.
Then this is the gun script for damaging the player.
local function hit(plr, part)
–//Initialize || Checks
if not canShoot() then return end
if not part then return end
--//Get humanoid root part
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart")
if rootPart then
--//Check distance
if (rootPart.CFrame.p - part.CFrame.p).magnitude <= range.Value then --//Check range
--//Get humanoid
local humanoid
--//Check if part was a hat/acessory
if part.Name == "Handle" then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
else
humanoid = part.Parent:FindFirstChild("Humanoid")
end
if humanoid and humanoid.Health > 0 then --//Do nothing if humanoid is dead
local newDamage = damage.Value
--//Check hit
if part.Name == "Head" then
newDamage = newDamage * headMultiplier.Value
--//Headshot related handling
local soundCopy = headshotSound:Clone()
soundCopy.Parent = part
soundCopy:Play()
end
--//Apply damage
humanoid:TakeDamage(newDamage)
end
end
end
end
Also side note, there is a headshot bonus, and it did not work either.
The parts being hit are within a model therefore you’re incorrectly defining the character and humanoid.
Instead, try:
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
-- Do your stuff
end
I’m not sure if this is correct but it looks like in the morph the body parts are in a model. In your script part.Parent:FindFirstChild(“Humanoid”) which would check if the humanoid was inside of the model instead the character model.
Solution
do part.Parent.Parent:FindFirstChild(“Humanoid”)
local function hit(plr, part)
–//Initialize || Checks
if not canShoot() then return end
if not part then return end
--//Get humanoid root part
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart")
if rootPart then
--//Check distance
if (rootPart.CFrame.p - part.CFrame.p).magnitude <= range.Value then --//Check range
--//Get humanoid
local humanoid = part.Parent:FindFirstChild("Humanoid")
--//Check if part was a hat/acessory
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
if humanoid and humanoid.Health > 0 then --//Do nothing if humanoid is dead
local newDamage = damage.Value
--//Check hit
if part.Name == "Head" then
newDamage = newDamage * headMultiplier.Value
--//Headshot related handling
local soundCopy = headshotSound:Clone()
soundCopy.Parent = part
soundCopy:Play()
end
--//Apply damage
humanoid:TakeDamage(newDamage)
end
end
end
end
end