Trying to make a part do damage to a player when touched but the output is saying that the "Humanoid isn't a valid member of script" and I don't really understand what it means.
And if you're wondering what I wrote then here it is.
function part() part = script.Parent if script.Parent.Touched then script.Parent.Parent.CanDamage = true game.Players.LocalPlayer.Humanoid:TakeDamage(15) if script.Parent.TouchEnded then script.Parent.Parent.CanDamage = false end end end part()
There are a few problems with this code. One, is there is no need to put it all in a function. You can simple do something like this. Put this in a serverscript under the part you w ant to damage people:
local db = false script.Parent.Touched:Connect(function(obj) local hum = obj.Parent:FindFirstChild("Humanoid") if not hum then return end if db == true then return end db = true hum:TakeDamage(15) wait(.5) db = false end)
This proposes quuick and easy solution to your problem. I also added a debounce so it doesent do 3 million damage out of nowhere when you only want 15.
You didn't define the player's character. This is a common mistake though, so don't worry.
local canDamage = script.Parent.CanDamage.Value -- change this to the value of the candamage value function partTouched(hit) local part = script.Parent canDamage = true if canDamage == true then hit.Parent:FindFirstChild("Humanoid"):TakeDamage(15) end end function partUntoched() canDamage = false end script.Parent.Touched:connect(part) script.Parent.TouchEnded:connect(partUntouched)
debounce = true script.Parent.Touched:Connect(function(hit) if debounce then debounce = false if hit.parent:FindFirstChild("Humanoid") then hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 15 wait(1) debounce = true end end end)
this will only damage the humanoid when it can find a humanoid and it got a 1 sec cooldown from the debounce if you dont want the cooldown for some weird reason then just delete them and the wait