So I have a script inside of a part called 'Glass'
Whenever something touches it with a Parent named 'Zombie' it takes away one from a value called 'Health' in the Part.
The script works fine, if the zombie touches it first. But if the player touches it first, then the zombie won't make any change to it.
I think I know how to fix this, but I'm not sure. I think I have to use 'else return' somewhere, but everywhere i tried to put it it didn't work.
This is the script inside the glass part:
local db = 0
local health = script.Parent:WaitForChild("Health")
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local human = hit.Parent:findFirstChild("Humanoid")
if db == 0 then
db = 1
if hit.Parent.Name == "Zombie" then
health.Value = health.Value - 1
print("ow")
print(health.Value)
wait(math.random(1,3))
db = 0
end
end
end
script.Parent.Touched:connect(onTouched)

2 comments
Man, I feel stupid. Well I guess that's what this website is for. It works too. Thanks so much! (Why is this post downvoted :I)
No problem!