I am making an item that promotes humanoid.health.But nothing happens. Why?
local Player = game:GetService("Players")
local SparksHeal = script.Parent:WaitForChild("SparksHeal")
script.Parent.Handle.Touched:Connect(function(hit)
local CarHumanoid = hit.Parent:FindFirstChild("Humanoid")
if CarHumanoid then
CarHumanoid.Health +=1
SparksHeal.Enabled = true
end
SparksHeal.Enabled = false
end)
Oh ok, like a Healing tool, and the user can heal other players?
If you want to use the Touched event, try adding an invisible collision box welded to the handle, big enough to actually collide with other players, and connect the Touched event to tat invisible collision box.
Or you could do it, on Tool.Activated and getting a Target player to heal, reading distance and the most closer player that is inside a range.
Or any other mechanic in which the user of the tool chooses the target player to heal
That car has a Humanoid? the one you want to heal?
In that case, do not use the touched event to get the Humanoid instance. Get the Humanoid target from a different mechanic, like, showing a prompt or something the player can Heal the car.
If you still want to use the Touched event, check the prints you get from the Touch event, when colliding with the car, first dont get on the ground, just touch the car with the tool to check you are getting prints
local Player = game:GetService("Players")
local SparksHeal = script.Parent:WaitForChild("SparksHeal")
script.Parent.Handle.Touched:Connect(function(hit)
local CarHumanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid", true) or hit.Parent.Parent:FindFirstChildWhichIsA("Humanoid", true) -- further searching purposes
if CarHumanoid then
CarHumanoid.Health = CarHumanoid.Health + 1 -- addition precaution instead of using +=
SparksHeal.Enabled = true
end
SparksHeal.Enabled = false
end)
Player selects the car to be Healed by using a Prompt or something you prefer that spawns on the car when player is holding the Tool, and then on Tool.Activate regen the car’s Health