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: Script with no errors, will not work.

Previous Thread :: Next Thread 
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
15 Dec 2013 09:55 PM
The problem is it will not print "Can not purchase" and will not Clone.
So it has to do with the check if user has the gear, everything else is fine.


script.Parent.Weapon_Shop.Weapon_Info.Purchase.MouseButton1Click:connect(function()
local check_Weapons = script.Parent.Parent.Parent.Parent.Parent.ServerStorage.Weapons:GetChildren()
local get_Weapons = script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text
local get_Users_Weapons = script.Parent.Parent.Parent.StarterGear:GetChildren()
for i = 1,#check_Weapons do
if check_Weapons[i].Name == get_Weapons then
for i = 1,#get_Users_Weapons do
if script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text == get_Users_Weapons[i].Name then
print("Can not purchase.")
else
game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.Backpack
game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.StarterGear
end
end
end
end
end)
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
15 Dec 2013 09:56 PM
Stop reposting this!
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
15 Dec 2013 09:57 PM
This is the 3rd time, I have been trying to get this fixed for 3 days.
I will not stop posting it(once a day kill me...) until someone cant help me fix this.
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
15 Dec 2013 11:26 PM
Use different variables for the for loops.
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
15 Dec 2013 11:55 PM
I don't know what your the problem is, but take a look at this code, see how much cleaner it looks then your code. It might have fixed the bug, too.

local player = script.Parent.Parent.Parent
local current_weapons = player.StarterGear
local weapons = game.ServerStorage.Weapons
local weapon_info = script.Parent.Weapon_Shop.Weapon_Info
local weapon_name = weapon_info.Weapon_Name.Text

local function purchase_weapon()
if current_weapons:FindFirstChild(weapon_name) then
print("You already have this weapon!")
return
end
weapons[weapon_name]:Clone().Parent = player.StarterPack
weapons[weapon_name]:Clone().Parent = player.Backpack
end

if weapons[weapon_name] then
weapon_info.Purchase.MouseButton1Click:connect(purchase_weapon)
else
Print("Unknown weapon name; Who set me up?")
end
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 01:16 AM
It's StarterGear not StarterPack.
Also I prefer people to not make me scripts, I'd just like help fixing mine.
Report Abuse
PiggyJingles is not online. PiggyJingles
Joined: 13 Jan 2009
Total Posts: 2472
16 Dec 2013 01:31 AM
If you are going to be a scrub and ignore repost this, tell us what this is supposed to do versus what it is actually doing.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 01:49 AM
It's suppose to clone and item into the users StarterGear and Backpack if the user does not have the item.
Just like a shop but I do not want to use to have more then one of the same gears, witch is the part I cant get to work.
If I take this away everything works fine.

I have try'ed every way I cant think of to do this and nothing works.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 10:00 AM
Here changed it a bit, once this part gets fixed I will add the rest.

script.Parent.Weapon_Shop.Weapon_Info.Purchase.MouseButton1Click:connect(function()
local get_Weapon = script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text
local check_User = script.Parent.Parent.Parent.StarterGear:GetChildren()
for i = 1, #check_User do
if check_User[i].Name == get_Weapon then
print("Print 1")
else
print("Print 2")
end
end
end)

This is the part of the script that does not work, at all.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 03:39 PM
Bump...
Sense this method is not working, can someone give me other ideas of how I could do this a different way.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 08:20 PM
Bump
Report Abuse
HAXO is not online. HAXO
Joined: 19 Mar 2010
Total Posts: 690
16 Dec 2013 08:24 PM
I'll try re-writing this.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 08:25 PM
Please don't.
I do not like people creating code for me.
Anything but that.
Report Abuse
HAXO is not online. HAXO
Joined: 19 Mar 2010
Total Posts: 690
16 Dec 2013 08:30 PM
Original Version:

script.Parent.Weapon_Shop.Weapon_Info.Purchase.MouseButton1Click:connect(function()
local check_Weapons = script.Parent.Parent.Parent.Parent.Parent.ServerStorage.Weapons:GetChildren()
local get_Weapons = script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text
local get_Users_Weapons = script.Parent.Parent.Parent.StarterGear:GetChildren()
for i = 1,#check_Weapons do
if check_Weapons[i].Name == get_Weapons then
for i = 1,#get_Users_Weapons do
if script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text == get_Users_Weapons[i].Name then
print("Can not purchase.")
else
game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.Backpack
game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.StarterGear
end
end
end
end
end)




Re-Writen:

script.Parent.Weapon_Shop.Weapon_Info.Purchase.MouseButton1Click:connect(function() local check_Weapons = script.Parent.Parent.Parent.Parent.Parent.ServerStorage.Weapons:GetChildren() local get_Weapons = script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text local get_Users_Weapons = script.Parent.Parent.Parent.StarterGear:GetChildren() for _,cW in next, check_Weapons do if cW.Name == get_Weapons then for gUW in next, get_Users_Weapons do if script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text == gUW.Name then else game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.Backpack game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.StarterGear end end end end end)




I found your problem while re-writing your code. Both your for loops use the same variable (i) change one to a different letter and it should work.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 10:05 PM
Lol wow, you know that just might be the problem.
This is what almost a year of no lua does to a person ._.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 10:10 PM
That cant be the problem due to the fact that this script below does not even work and there is only 1 for loop.

script.Parent.Weapon_Shop.Weapon_Info.Purchase.MouseButton1Click:connect(function()
local get_Weapon = script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text
local check_User = script.Parent.Parent.Parent.StarterGear:GetChildren()
for i = 1, #check_User do
if check_User[i].Name == get_Weapon then
print("Print 1")
else
print("Print 2")
end
end
end)

Report Abuse
HAXO is not online. HAXO
Joined: 19 Mar 2010
Total Posts: 690
16 Dec 2013 10:14 PM
Does the output say anything?
But at least you have one problem out of the way.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 10:24 PM
Ya, but not the output says nothing.
Neither prints.
Report Abuse
PiggyJingles is not online. PiggyJingles
Joined: 13 Jan 2009
Total Posts: 2472
16 Dec 2013 10:26 PM
Add more prints then, see where the problem is?
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 10:27 PM
Using the code I posted in my main post(the first one you see when you click the thread.)
If I put the item in Backpack and StarterGear it says "Can not purchase.".

So the cloning seems to be the only problem.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 10:30 PM
Ok so I did this

script.Parent.Weapon_Shop.Weapon_Info.Purchase.MouseButton1Click:connect(function()
local check_Weapons = script.Parent.Parent.Parent.Parent.Parent.ServerStorage.Weapons:GetChildren()
local get_Weapons = script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text
local get_Users_Weapons = script.Parent.Parent.Parent.StarterGear:GetChildren()
for i = 1,#check_Weapons do
print("Print 1")
if check_Weapons[i].Name == get_Weapons then
print("Print 2")
for k = 1,#get_Users_Weapons do
print("Print 3")
if script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text == get_Users_Weapons[k].Name then
print("Can not purchase.")
else
print("Print 4")
game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.Backpack
game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.StarterGear
end
print("Print 5")
end
print("Print 6")
end
print("Print 7")
end
print("Print 8")
end)



and the output was this.

Print 1
Print 7
Print 1
Print 7
Print 1
Print 2
Print 6
Print 7
Print 1
Print 7
Print 1
Print 7
Print 1
Print 7
Print 1
Print 7
Print 1
Print 7
Print 1
Print 7
Print 1
Print 7
Print 1
Print 7
Print 1
Print 7
Print 8
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
16 Dec 2013 11:47 PM
Bump
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
17 Dec 2013 12:33 AM
The thing about using the same variables, I pointed that out 2 days ago. ARe you telling me that you totally ignored my post? wow thanks.
Report Abuse
TheBlackCloth is not online. TheBlackCloth
Joined: 01 Jul 2013
Total Posts: 219
17 Dec 2013 01:04 AM
I do not remember that.
Report Abuse
HAXO is not online. HAXO
Joined: 19 Mar 2010
Total Posts: 690
17 Dec 2013 07:46 AM
Try this and check the output:




script.Parent.Weapon_Shop.Weapon_Info.Purchase.MouseButton1Click:connect(function()
local check_Weapons = script.Parent.Parent.Parent.Parent.Parent.ServerStorage.Weapons:GetChildren()
local get_Weapons = script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text
local get_Users_Weapons = script.Parent.Parent.Parent.StarterGear:GetChildren()
for i = 1,#check_Weapons do
print(">Stage1: Searching Weapon Bank")
if check_Weapons[i].Name == get_Weapons then
print(">Stage2: Weapon("..check_Weapons[i].Name..") Matches "..get_Weapons)
for k = 1,#get_Users_Weapons do
print(">Stage3: Searching For Duplicate; Testing \""..script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text.."\" To \""..get_Users_Weapons[k].Name.."\"")
if script.Parent.Weapon_Shop.Weapon_Info.Weapon_Name.Text == get_Users_Weapons[k].Name then
print(">Stage4_OptionA: Duplicate Found; Ending Function")
else
print(">Stage4_OptionB: No Duplicate Fount")
game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.Backpack
game.ServerStorage.Weapons[get_Weapons]:Clone().Parent = script.Parent.Parent.Parent.StarterGear
end
print(">Stage4_Finished")
end
print(">Stage3_Finished")
end
print(">Stage2_Finished")
end
print(">Stage1_Finished")
end)
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