generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Forage tool not loading properly

Previous Thread :: Next Thread 
yyyyyy09 is not online. yyyyyy09
Joined: 13 Mar 2010
Total Posts: 10
01 Feb 2014 02:08 AM
So the forage tool i'm using has a white bar and whenever i forage something, there is a loading bar that's supposed to go across the screen but its not going across :/ here's the code:(some of its probably messed up because of copying)
wait(1)

local tool = script.Parent
local frame = tool.Frame
local label = frame.Label
local timeBar = frame.TimeBar

local debounce = true

function getDist(a, b)
return (a - b).magnitude
end

function getForage(part)
local parent = part.Parent

if parent ~= nil then
local val = parent:findFirstChild("Forage")

if val == nil then
val = part:findFirstChild("IForage")
end

if val == nil then
val = part:findFirstChild("CForage")
end

if val == nil then
return false, nil
else
return true, val
end
end
end

function getLabel(part)
local string = part.Name

return string
end

function onMouseMove(mouse)
local targ = mouse.Target

local player = tool.Parent.Parent
local char = player.Character
local head = char.Head

label.Text = ""

if targ ~= nil then
local can, type = getForage(targ)
if (can and type.Name == "Forage") or not targ.Locked then
if getDist(head.Position, mouse.hit.p) < 15 then
label.Text = getLabel(targ)
end
elseif can and type.Name == "IForage" then
if getDist(head.Position, mouse.hit.p) < 15 then
local real = game.Lighting.IF:findFirstChild(type.Value)
if real ~= nil then
label.Text = getLabel(real)
end
end
elseif can and type.Name == "CForage" then
if getDist(head.Position, mouse.hit.p) < 15 then
local ot = game.Lighting.CF:findFirstChild(type.Value)
if ot ~= nil then
real = math.random(1, 2)
if real == 1 then
real = "Pizza"
elseif real == 2 then
real = "Lemonade"
end
label.Text = getLabel(real)
end
end
end
end
end

function onSelected(mouse)
local player = tool.Parent.Parent

frame.Parent = player.PlayerGui.ScreenGui

mouse.Move:connect(function() onMouseMove(mouse) end)

mouse.Button1Down:connect(function()
local char = player.Character
local head = char.Head
local inven = player.Inventory:GetChildren()

local targ = mouse.Target

if targ ~= nil then
local can, type = getForage(targ)
if (can and type.Name == "Forage") or not targ.Locked then
if getDist(head.Position, mouse.hit.p) < 15 then
if debounce then
if player.Inventory.One.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.One.Value = targ

targ.Parent = player.Inventory

elseif player.Inventory.Two.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Two.Value = targ

targ.Parent = player.Inventory

elseif player.Inventory.Three.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Three.Value = targ

targ.Parent = player.Inventory

elseif player.Inventory.Four.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Four.Value = targ

targ.Parent = player.Inventory

elseif player.Inventory.Five.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Five.Value = targ

targ.Parent = player.Inventory

elseif player.Inventory.Six.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Six.Value = targ

targ.Parent = player.Inventory

elseif player.Inventory.Seven.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Seven.Value = targ

targ.Parent = player.Inventory

elseif player.Inventory.Eight.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Eight.Value = targ

targ.Parent = player.Inventory

elseif player.Inventory.Nine.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Nine.Value = targ

targ.Parent = player.Inventory

elseif player.Inventory.Ten.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = targ:GetMass() / 25

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Ten.Value = targ

targ.Parent = player.Inventory
end
end
end
elseif can and type.Name == "IForage" then
if getDist(head.Position, mouse.hit.p) < 15 then
if debounce then
local real = game.Lighting.IF:findFirstChild(type.Value)
if real ~= nil then
c = real:Clone()
if player.Inventory.One.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.One.Value = c

c.Parent = player.Inventory
elseif player.Inventory.Two.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Two.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Three.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Three.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Four.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Four.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Five.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Five.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Six.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Six.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Seven.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Seven.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Eight.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Eight.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Nine.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Nine.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Ten.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Ten.Value = c

c.Parent = player.Inventory
end
end
end
end

elseif can and type.Name == "CForage" then
if getDist(head.Position, mouse.hit.p) < 15 then
if debounce then
local ot = game.Lighting.CF:findFirstChild(type.Value)
real = math.random(1, 2)
if real == 1 then
real = ot.Pizza
elseif real == 2 then
real = ot.Lemonade
end
if real ~= nil then
c = real:Clone()
if player.Inventory.One.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.One.Value = c

c.Parent = player.Inventory
elseif player.Inventory.Two.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Two.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Three.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Three.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Four.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Four.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Five.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Five.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Six.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Six.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Seven.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Seven.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Eight.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Eight.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Nine.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Nine.Value = c

c.Parent = player.Inventory

elseif player.Inventory.Ten.Value == nil then

local bp = targ:findFirstChild("BodyPosition")

if bp ~= nil then
bp:remove()
end

local time = c:GetMass() / 5

local spd = char.Humanoid.WalkSpeed
char.Humanoid.WalkSpeed = 0

debounce = false

for t = 0, time, 0.05 do
timeBar.Size = UDim2.new(t / time, 0, 1, 0)
wait(0.05)
end

debounce = true

char.Humanoid.WalkSpeed = spd

timeBar.Size = UDim2.new(0, 0, 1, 0)

player.Inventory.Ten.Value = c

c.Parent = player.Inventory
end
end
end
end
end
end
end)
end

function onDeselected()
frame.Parent = tool

if example ~= nil then
example.Parent = nil
end
end

tool.Selected:connect(onSelected)
tool.Deselected:connect(onDeselected)
Report Abuse
jakedies is not online. jakedies
Joined: 19 Oct 2008
Total Posts: 86
01 Feb 2014 02:09 AM
This is by far the longest and possibly most inefficient (I didn't read it) script I have seen for a forge tool
Report Abuse
yyyyyy09 is not online. yyyyyy09
Joined: 13 Mar 2010
Total Posts: 10
01 Feb 2014 02:02 PM
It is not inefficient it is just saying if the value of inventory space one is nil then put the part in there for example: if player.Inventory.One.Value == nil then.
the only problem is, is that the loading bar is not going a across
Report Abuse
Kyrothehero is not online. Kyrothehero
Joined: 14 Aug 2012
Total Posts: 306
01 Feb 2014 02:08 PM
if you looked at the output in solo mode and saw where the error was, you could show us that instead of 100 lines of code.
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
01 Feb 2014 02:11 PM
Try cleaning up the code and make it more efficient, believe it or not sometimes pure sloppiness can ruin code.

Because the code is so big though, I'm not going to simplify it until you try and repost a simplified code.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image