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

This script keeps outputting "Touched is not a valid member of tool"?

Asked by 7 years ago
ball = script.Parent
damage = 10

r = game:service("RunService")

last_sound_time = r.Stepped:wait()

function onTouched(hit)

    local now = r.Stepped:wait()

    if (now - last_sound_time > .1) then
        ball.Boing:play()
        last_sound_time = now
    else
        return
    end

    local humanoid = hit.Parent:findFirstChild("Humanoid")
    local zombie = hit.Parent:findFirstChild("Zombie")
    if humanoid~=nil then
        tagHumanoid(humanoid)
        humanoid.Health = humanoid.Health - damage
        wait(2)
        untagHumanoid(humanoid)
        connection:disconnect()
    else
        damage = damage / 5
        if damage < 2 then
            connection:disconnect()
        end
    end
end

function tagHumanoid(humanoid)
    -- todo: make tag expire
    local tag = ball:findFirstChild("creator")
    if tag ~= nil then
        local new_tag = tag:clone()
        new_tag.Parent = humanoid
    end
end

function tagZombie(zombie)
    -- todo: make tag expire
    local tag = ball:findFirstChild("creator")
    if tag ~= nil then
        local new_tag = tag:clone()
        new_tag.Parent = zombie
    end
end


function untagHumanoid(humanoid)
    if humanoid ~= nil then
        local tag = humanoid:findFirstChild("creator")
        if tag ~= nil then
            tag.Parent = nil
        end
    end
end

connection = ball.Touched:connect(onTouched)


t, s = r.Stepped:wait()
d = t + 5.0 - s
while t < d do
    t = r.Stepped:wait()
end

ball.Parent = nil

Line of error: connection = ball.Touched:connect(onTouched)

Not exactly sure whats wrong with it so if you can tell me how to fix it and explain why the error happens, that would be nice of you.

0
Do you mean ball = script.Parent.Handle? OldPalHappy 1477 — 7y
0
Nah it should be ball = script.Parent it is inside the tool not the handle windstrike 27 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

This means that your script is a child of a tool, and by setting ball to script.Parent you are reffering to that tool. You need to change that line or place your script inside a part. Here is an explaination of what you might be doing wrong

Ad

Answer this question