Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Ontouch script not working?

Asked by 8 years ago

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)
0
is the humanoid's name Drooling Zombie? HungryJaffer 1246 — 8y
0
Yes CorruptBullet 5 — 8y
0
FirstFindChild returns a child with the same name as the string. so if you try to find the humanoid's name, it should be humanoid. HungryJaffer 1246 — 8y
0
@Hungryjaffer I just fixed it so finds the models name as Drooling zombie and it still does not work CorruptBullet 5 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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.

0
No. Between parentheses you can put whatever you want on Touched event. DragonOfWar900 397 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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.

0
I still have one problem it only loses health 1 time what I do? CorruptBullet 5 — 8y

Answer this question