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

Script Works when testing but not online when published?

Asked by 8 years ago

I have a bow script that works when i test play it in studio, but when i publish the game and play it online the GUI doesn't show up and the bow doesn't work. Why is that? Thanks for any help and suggestions!

local TOOL = script.Parent

local DAMAGE = 30
local RANGE = 50
local REST_TIME = 0.5
local CRIT_MULT = 2

local DEBOUNCE = true

local AMMO_TYPE = "ARROW"
local AMMO_BOX = TOOL.Ammo
local AMMO_GUI = TOOL.ScreenGui
local AMMO_NUM_LABEL = AMMO_GUI.Frame.TotalAmmoLabel
local AMMO_TYPE_LABEL = AMMO_GUI.Frame.AmmoTypeLabel
local CURRENT_SHOT = nil

function getPC()
    local char = TOOL.Parent
    local player = game.Players:GetPlayerFromCharacter(char)

    return player, char
end

function humanCheck(part)
    local parent = part.Parent

    if parent == nil then
        return false
    end

    local humanoid = parent:findFirstChild("ANIMAL")

    if humanoid ~= nil then
        return true
    end

    return false
end

function distanceCheck(part)
    local player, char = getPC()
    local head = char.Head

    local dist = (head.Position - part.Position).magnitude

    return (dist < RANGE)
end

function ammoCheck(part)
    local typeValue = part:findFirstChild("AmmoType")

    if typeValue ~= nil then
        return (typeValue.Value == AMMO_TYPE)
    end
end

function hasAmmo()
    local ammo = AMMO_BOX:GetChildren()
    local ammoNum = #ammo

    return (ammoNum > 0)
end

function canHit(part)
    local bool = false

    bool = (bool or humanCheck(part))
    bool = (bool and distanceCheck(part))
    bool = (bool and hasAmmo())

    return bool
end

function canPickup(part)
    local bool = false

    bool = (bool or ammoCheck(part))

    return bool
end

function attack(body_part, human)
    body_part = body_part.Name

    local health = human.HEALTH

    local final_damage = DAMAGE + CURRENT_SHOT.Damage.Value

    if body_part == "Head" or body_part == "Torso" then
        health.Value = health.Value - (final_damage * CRIT_MULT)
    end

    if body_part == "Right Arm" or body_part == "Left Arm" then
        health.Value = health.Value - (final_damage / CRIT_MULT)
    end

    if body_part == "Right Leg" or body_part == "Left Leg" then
        health.Value = health.Value - (final_damage)
    end
end

function updateAmmo()
    local ammo = AMMO_BOX:GetChildren()
    local ammo_num = #ammo

    CURRENT_SHOT = ammo[1]

    if CURRENT_SHOT ~= nil then
        AMMO_NUM_LABEL.Text = "Ammo: "..ammo_num
        AMMO_TYPE_LABEL.Text = "Current: "..CURRENT_SHOT.Name
    else
        AMMO_NUM_LABEL.Text = "No ammo!"
        AMMO_TYPE_LABEL.Text = ""
    end
end

function slash()
    local s = Instance.new("StringValue")
    s.Name = "toolanim"
    s.Value = "Slash"
    s.Parent = TOOL
end

function fire(v)


    local vCharacter = TOOL.Parent

    local vPlayer = game.Players:playerFromCharacter(vCharacter)


    local missile = TOOL.Bolt:Clone()

    -- find firing direction

    local v1 = -TOOL.Bolt.CFrame.lookVector.unit
    local v2 = v.unit


    local dot = (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z)
    local ang = math.acos(dot)

    -- test if in cone
    if (ang < 3.14 / 8) then

    else
        -- not in cone, find projection
         --n = v1 x v2
        --local n = Vector3.new(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.z * v2.y - v1.y * v2.x)

        --return
    end


    --missile.CFrame = Tool.Bolt.CFrame + (Tool.Bolt.CFrame.lookVector * -8)
    missile.CFrame = TOOL.Bolt.CFrame + (v * 8)

    missile.Transparency = 0

    missile.Velocity =  v * 150

    missile.Name = "CrossbowBolt"

    missile.Elasticity = 0


    local force = Instance.new("BodyForce")

    force.force = Vector3.new(0,150,0)

    force.Parent = missile

    missile.BodyGyro.cframe = CFrame.new(Vector3.new(0,0,0), -TOOL.Bolt.CFrame.lookVector.unit)
    missile.BodyGyro.maxTorque = Vector3.new(5e5,5e5,5e5)



    local new_script = script.Parent.CrossbowBoltScript:clone()

    new_script.Disabled = false

    new_script.Parent = missile



    local creator_tag = Instance.new("ObjectValue")

    creator_tag.Value = vPlayer

    creator_tag.Name = "creator"

    creator_tag.Parent = missile


    missile.Parent = game.Workspace


end


TOOL.Enabled = true

function onActivated()


    if not TOOL.Enabled then

        return

    end

    TOOL.Enabled = false
    end

function onButton1Down(mouse)
    if not DEBOUNCE then return end

    DEBOUNCE = false

    local character = TOOL.Parent;
    local humanoid = character.Humanoid
    local targ = mouse.Target
    local targetPos = humanoid.TargetPoint
    local lookAt = (targetPos - character.Head.Position).unit


    if canHit(targ) then
        local enemy = targ.Parent
        local human = enemy.ANIMAL

        attack(targ, human)

        CURRENT_SHOT:remove()
        fire(lookAt)

    wait(2)

    TOOL.Enabled = true

        updateAmmo()    
    end

    if canPickup(targ) then
        targ.Parent = AMMO_BOX

        updateAmmo()
    else
        wait(REST_TIME)
    end

    DEBOUNCE = true
end

function onEquipped(mouse)
    local player, char = getPC()

    AMMO_GUI.Parent = player.PlayerGui
    updateAmmo()

    AMMO_BOX.Parent = player.Backpack

    mouse.Button1Down:connect(function()
        onButton1Down(mouse)
    end)
end

function onUnequipped()
    local player, char = getPC()

    AMMO_GUI.Parent = TOOL

    AMMO_BOX.Parent = TOOL
end


script.Parent.Activated:connect(onActivated)
TOOL.Equipped:connect(onEquipped)
TOOL.Unequipped:connect(onUnequipped)


0
i bet taslem didnt even read all 278 lines koolkid8099 705 — 8y
0
haha ^ but thanks taslem, so far its looking like that was the problem, most of my scripts were scripts not localscripts, and that also fixed the testing mode in studio so it isn't slow anymore. Gwolflover 80 — 8y

1 answer

Log in to vote
0
Answered by 6 years ago

Im not an expert on stuff like that, but lowercase C in script.Parent.Activated:connect() and other parts like that is deprecated and should be a capital letter.

Ad

Answer this question