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

Gun fires, but bullet does not kill Zombies? [UPDATE] [NEED ANSWER]

Asked by 10 years ago

UPDATE: Hit is defined, line 12

This script is inside a tool, meant to kill Zombies (Hostile NPCs with a Humanoid named Zombie), and when the tool is fired the ball(bullet) kills the Zombie. It works on test mode in ROBLOX Studio, but not when a physically play the game. Script looks very long, but all I worry about are lines 12-34

--Script looks very long, but all I worry about are lines 12-34
ball = script.Parent
damage = math.random(30,60)
local hitt = false

HitSound = Instance.new("Sound")
HitSound.Name = "HitSound"
HitSound.SoundId = "http://www.roblox.com/asset/?id=11945266"
HitSound.Pitch = .8
HitSound.Volume = 1
HitSound.Parent = ball

function onTouched(hit)
    if hit.Parent:findFirstChild("ForceField") ~= nil then return end
    if hit.CanCollide == false and hit.Parent:findFirstChild("Zombie") == nil then return end
    if hit.Parent.className == "Hat" and hitt == false then
        hitt = true
        hit:BreakJoints()
        hit.Velocity = ball.Velocity
        hit.Parent.Parent = game.Workspace
    end

    if hit:findFirstChild("Metal") ~= nil and hitt == false then
        hitt = true
        for i = 1,math.random(1,3) do
            local j = Instance.new("Part")
            j.formFactor = "Plate"
            j.Size = Vector3.new(1,.4,1)
            j.BrickColor = BrickColor.new("Bright yellow")
            j.CanCollide = false
            j.Velocity = Vector3.new(math.random(-10,10),math.random(-10,10),math.random(-10,10))
            j.CFrame = script.Parent.CFrame
            j.Parent = game.Workspace
        end
    end

    local humanoid = hit.Parent:findFirstChild("Zombie")

    if humanoid ~= nil and hitt == false then
        hitt = true
        tagHumanoid(humanoid)
        if hit.Name == "Head" then
            humanoid.Health = humanoid.Health - damage * 2
        elseif hit.Name == "Torso" then
            humanoid.Health = humanoid.Health - damage * 1.5
        else
            humanoid.Health = humanoid.Health - damage
        end
        wait(.2)
        untagHumanoid(humanoid)
    end
    if hitt == true then
        HitSound:play()
        ball.Parent = nil
    end
end

function tagHumanoid(humanoid)
    local tag = ball:findFirstChild("creator")
    if tag ~= nil then
        local new_tag = tag:clone()
        new_tag.Parent = humanoid
    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)

while true do
wait(.01)
if damage < 0 then
break
else
damage = damage - .2
end
end

ball.Parent = nil

The ball(bullet) spawns when fired, but does not take any damage to the Zombie. Thanks!

2 answers

Log in to vote
0
Answered by 10 years ago

I see that it looks like your using 2 variables, hit and hitt, but it seems like you only defined "hitt"

0
Hit is defined, line 12 "function onTouched(hit)" PyccknnXakep 1225 — 10y
0
Oops sorry xD iPrepared 30 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Usually when it works in Studio but not online that means you need it in a localscript. Just a guess.

0
I'll try that out PyccknnXakep 1225 — 10y
0
Nope, still doesn't work :( PyccknnXakep 1225 — 10y

Answer this question