So basically all I want this script to do if a zombie touches it the health on the gui goes down by one. But for some reason it's not working and I think I did something wrong.
function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") local zombie = part.Parent:FindFirstChild("Humanoid").Name == "Drooling Zombie" local n = PlayerGui.Notice.Box.Health1.Health.Value if humanoid~=nil and zombie~=nil then for i, v in ipairs(game.Players:GetChildren()) do v.n = (n.Value -1) v.PlayerGui.Notice.Box.Health1.Text = n.Value end end end script.Parent.Touched:connect(onTouch)
On your function parentheses you put in part instead of hit so maybe Lua is not picking it up as a touch/hit
function onTouch(hit) local humanoid = part.Parent:FindFirstChild("Humanoid") local zombie = part.Parent:FindFirstChild("Humanoid").Name == "Drooling Zombie"
local n = PlayerGui.Notice.Box.Health1.Health.Value
if humanoid~=nil and zombie~=nil then for i, v in ipairs(game.Players:GetChildren()) do v.n = (n.Value -1) v.PlayerGui.Notice.Box.Health1.Text = n.Value end
end end
script.Parent.Touched:connect(onTouch)
if not im not sure what it is.
You did something wrong there:
local zombie = part.Parent:FindFirstChild("Humanoid").Name == "Drooling Zombie"
local zombie =
is supposed to be used as a variable creation. I don't know if your trying to create a variable or modify the humanoids name.
If your trying to modify the humanoids name, don't use local zombie=
. Use:
humanoid.Name == "Drooling Zombie"
Also, if you want to modify a value of a Value
Object you need to make sure that you have valueObject.Value:
valueObject.Value = whateverValue
On line 12, your not putting v
at the start of n.Value
. The script doesn't know whats n
because there's no n
variable. So i think it would be
v.PlayerGui.Notice.Box.Health1.Text = v.n.Value
So the script would be:
function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") humanoid.Name == "Drooling Zombie" local n = PlayerGui.Notice.Box.Health1.Health.Value if humanoid~=nil then for i, v in ipairs(game.Players:GetChildren()) do v.n = (n.Value -1) v.PlayerGui.Notice.Box.Health1.Text = v.n.Value end end script.Parent.Touched:connect(onTouch)
Protip: Use The output.