Script Works when testing but not online when published?
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!
001 | local TOOL = script.Parent |
010 | local AMMO_TYPE = "ARROW" |
011 | local AMMO_BOX = TOOL.Ammo |
012 | local AMMO_GUI = TOOL.ScreenGui |
013 | local AMMO_NUM_LABEL = AMMO_GUI.Frame.TotalAmmoLabel |
014 | local AMMO_TYPE_LABEL = AMMO_GUI.Frame.AmmoTypeLabel |
015 | local CURRENT_SHOT = nil |
018 | local char = TOOL.Parent |
019 | local player = game.Players:GetPlayerFromCharacter(char) |
024 | function humanCheck(part) |
025 | local parent = part.Parent |
027 | if parent = = nil then |
031 | local humanoid = parent:findFirstChild( "ANIMAL" ) |
033 | if humanoid ~ = nil then |
040 | function distanceCheck(part) |
041 | local player, char = getPC() |
042 | local head = char.Head |
044 | local dist = (head.Position - part.Position).magnitude |
046 | return (dist < RANGE) |
049 | function ammoCheck(part) |
050 | local typeValue = part:findFirstChild( "AmmoType" ) |
052 | if typeValue ~ = nil then |
053 | return (typeValue.Value = = AMMO_TYPE) |
058 | local ammo = AMMO_BOX:GetChildren() |
059 | local ammoNum = #ammo |
067 | bool = (bool or humanCheck(part)) |
068 | bool = (bool and distanceCheck(part)) |
069 | bool = (bool and hasAmmo()) |
074 | function canPickup(part) |
077 | bool = (bool or ammoCheck(part)) |
082 | function attack(body_part, human) |
083 | body_part = body_part.Name |
085 | local health = human.HEALTH |
087 | local final_damage = DAMAGE + CURRENT_SHOT.Damage.Value |
089 | if body_part = = "Head" or body_part = = "Torso" then |
090 | health.Value = health.Value - (final_damage * CRIT_MULT) |
093 | if body_part = = "Right Arm" or body_part = = "Left Arm" then |
094 | health.Value = health.Value - (final_damage / CRIT_MULT) |
097 | if body_part = = "Right Leg" or body_part = = "Left Leg" then |
098 | health.Value = health.Value - (final_damage) |
103 | local ammo = AMMO_BOX:GetChildren() |
104 | local ammo_num = #ammo |
106 | CURRENT_SHOT = ammo [ 1 ] |
108 | if CURRENT_SHOT ~ = nil then |
109 | AMMO_NUM_LABEL.Text = "Ammo: " ..ammo_num |
110 | AMMO_TYPE_LABEL.Text = "Current: " ..CURRENT_SHOT.Name |
112 | AMMO_NUM_LABEL.Text = "No ammo!" |
113 | AMMO_TYPE_LABEL.Text = "" |
118 | local s = Instance.new( "StringValue" ) |
127 | local vCharacter = TOOL.Parent |
129 | local vPlayer = game.Players:playerFromCharacter(vCharacter) |
132 | local missile = TOOL.Bolt:Clone() |
136 | local v 1 = -TOOL.Bolt.CFrame.lookVector.unit |
140 | local dot = (v 1. x * v 2. x) + (v 1. y * v 2. y) + (v 1. z * v 2. z) |
141 | local ang = math.acos(dot) |
144 | if (ang < 3.14 / 8 ) then |
156 | missile.CFrame = TOOL.Bolt.CFrame + (v * 8 ) |
158 | missile.Transparency = 0 |
160 | missile.Velocity = v * 150 |
162 | missile.Name = "CrossbowBolt" |
164 | missile.Elasticity = 0 |
167 | local force = Instance.new( "BodyForce" ) |
169 | force.force = Vector 3. new( 0 , 150 , 0 ) |
171 | force.Parent = missile |
173 | missile.BodyGyro.cframe = CFrame.new(Vector 3. new( 0 , 0 , 0 ), -TOOL.Bolt.CFrame.lookVector.unit) |
174 | missile.BodyGyro.maxTorque = Vector 3. new( 5 e 5 , 5 e 5 , 5 e 5 ) |
178 | local new_script = script.Parent.CrossbowBoltScript:clone() |
180 | new_script.Disabled = false |
182 | new_script.Parent = missile |
186 | local creator_tag = Instance.new( "ObjectValue" ) |
188 | creator_tag.Value = vPlayer |
190 | creator_tag.Name = "creator" |
192 | creator_tag.Parent = missile |
195 | missile.Parent = game.Workspace |
203 | function onActivated() |
206 | if not TOOL.Enabled then |
215 | function onButton 1 Down(mouse) |
216 | if not DEBOUNCE then return end |
220 | local character = TOOL.Parent; |
221 | local humanoid = character.Humanoid |
222 | local targ = mouse.Target |
223 | local targetPos = humanoid.TargetPoint |
224 | local lookAt = (targetPos - character.Head.Position).unit |
228 | local enemy = targ.Parent |
229 | local human = enemy.ANIMAL |
233 | CURRENT_SHOT:remove() |
243 | if canPickup(targ) then |
244 | targ.Parent = AMMO_BOX |
254 | function onEquipped(mouse) |
255 | local player, char = getPC() |
257 | AMMO_GUI.Parent = player.PlayerGui |
260 | AMMO_BOX.Parent = player.Backpack |
262 | mouse.Button 1 Down:connect( function () |
267 | function onUnequipped() |
268 | local player, char = getPC() |
270 | AMMO_GUI.Parent = TOOL |
272 | AMMO_BOX.Parent = TOOL |
276 | script.Parent.Activated:connect(onActivated) |
277 | TOOL.Equipped:connect(onEquipped) |
278 | TOOL.Unequipped:connect(onUnequipped) |