hello everyone this is my first post i need help with it. i have been doing a obby game so i tried to create a spinning killbrick thats is not collidable the problem is that when i make it non collidable it doesnt kill anymore. what should i do? i have been trying to fix this without success. here is the script in case you need it. script:
script.Parent.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then hit.Parent.TakeDamage = -3 end end)
The problem with that was TakeDamage()
was used incorrectly. Also as a side-note, :connect
is deprecated to please remember to use :Connect
. Additionally, you should be formatting your code correctly. Here is a working damage script:
local part = script.Parent part.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then local hum = hit.Parent:FindFirstChild("Humanoid") hum.Health = hum.Health -3 end end)
I believe this would be the answer:
script.Parent.Touched:connect(function(hit) if hit and hit:FindFirstAncestorOfClass('Model') then local Model = hit:FindFirstAncestorOfClass('Model') Model:WaitForChild('Humanoid'):TakeDamage(-3) end end)
but if you want it unformatted for easier copying:
script.Parent.Touched:connect(function(hit) if hit and hit:FindFirstAncestorOfClass('Model') then local Model = hit:FindFirstAncestorOfClass('Model') Model:WaitForChild('Humanoid'):TakeDamage(-3) end end)
Here's a damage script, Oh and in the future you can click the blue lua button when writing a post to highlight your code
local Damage = 100 script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') then hit.Parent.Humanoid:TakeDamage(Damage) end end)