I am wanting to make a flamethrower, and I have a script to make 3 parts used as the flame parts do damage. No matter how many attempts, it keeps on not doing damage on humanoids. I have done different types of systems in the function, and still nothing. Here’s my latest attempt:
--
local FlameThrower = script.Parent
local lowbar = FlameThrower.FireLowBar
local midbar = FlameThrower.FireMiddleBar
local highbar = FlameThrower.FireHighBar
local Players = game:GetService("Players")
local function OnTouched(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local humanoid = player:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(0)
if humanoid and FlameThrower.Activated then
humanoid:TakeDamage(10)
end
end
end
end
lowbar.Touched:Connect(OnTouched)
midbar.Touched:Connect(OnTouched)
highbar.Touched:Connect(OnTouched)
That piece of code will reference the Player for you, you want to keep that.
If you put a .Character next to your player variable, then it will reference the Character.
-- MODIFIED FUNCTION
local function OnTouched(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local humanoid = player.Character:FindFirstChild("Humanoid") -- .Character will reference your character
if humanoid then
humanoid:TakeDamage(0)
if humanoid and FlameThrower.Activated then
humanoid:TakeDamage(10)
end
end
end
end
If I didn’t answer your question coherently, please let me know. I’m unsure what you meant by “verse.”
local function OnTouched(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
if FlameThrower.Activated then
humanoid:TakeDamage(10)
end
end
end
end
Try this instead.
I don’t know why you had Humanoid:TakeDamage(0), but this function might fix your issue.
My logic was that if it recognizes a humanoid, it wouldn’t do damage (0) until activated, or left clicked.
(10)
I’m still a little new, so I might have made a faulty attempt. Basically, I tried having the touched system and Activated system work alongside each other.
I managed to figure out an idea that works. But despite that, since you at least were willing to help, I gave your post the solution for your troubles. Have a great day!
-BreeZ
P.S. if you wanna try it out for yourself, the game is Bloxity City!