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 » Game Design
Home Search
 

Re: Scripting help?

Previous Thread :: Next Thread 
tornadozebra is not online. tornadozebra
Joined: 02 Oct 2011
Total Posts: 316
30 Oct 2015 02:29 PM
So I'm doing an ammo kiosk like thing from Metro 2033, and every script I try doesn't work. It is in a GUI under a text label, and is supposed to exchange ammo once clicked.

local player = script.Parent.Parent.Parent.Parent.Parent
local gold = player.leaderstats.MGR --Put your currency after Leaderstats.
local Add = 20
local Gun1 = player.Backpack.Steyr.StoredAmmo
local Gun2 = player.Backpack.Ak47.StoredAmmo
local Cost = 10
----------------------------------------------------------------------------------------------------
script.Parent.MouseButton1Click:connect(function()
function clickOn()
print "Encounter"
if player.Backpack:FindFirstChild(Ak47)or player.Backpack:FindFirstChild(Steyr) then
if gold.value >=10 then
gold.value = gold.value - Cost
if player.Backpack:FindFirstChild(Ak47)then
Gun2.value = Gun2.value + Add
print "Purchase Complete : AK"
end
if player.Backpack:FindFirstChild(Steyr)then
Gun1.value = Gun1.value + Add
print "Purchase Complete : AUG"
end

end
end
script.Parent.MouseButton1Down:connect(ClickOn)
Report Abuse
hihixil is not online. hihixil
Joined: 28 Mar 2013
Total Posts: 322
30 Oct 2015 04:36 PM
WRONG. FRORUM.
Report Abuse
AuroJosh is not online. AuroJosh
Joined: 04 Oct 2015
Total Posts: 484
30 Oct 2015 04:42 PM
When you're finding the child do this

if player.Backpack:FindFirstChild("Ak47") or player.Backpack:FindFirstChild("Steyr") then

etc.



Who is dis? Dis is AuroJosh!
Report Abuse
cowsoncows is not online. cowsoncows
Joined: 11 Oct 2013
Total Posts: 2522
30 Oct 2015 04:46 PM
When you're finding the child do this

if player.Backpack:FindFirstChild("Ak47") or player.Backpack:FindFirstChild("Steyr") then

etc.[2]

quotes around the weapon name so it's a string.
Report Abuse
cowsoncows is not online. cowsoncows
Joined: 11 Oct 2013
Total Posts: 2522
30 Oct 2015 04:48 PM
Also I'm not sure if it matters in this case but your connection is (ClickOn), but the function's called clickon (no caps) try that too?
Report Abuse
AuroJosh is not online. AuroJosh
Joined: 04 Oct 2015
Total Posts: 484
30 Oct 2015 04:50 PM
Do this.

local player = script.Parent.Parent.Parent.Parent.Parent
local gold = player.leaderstats.MGR --Put your currency after Leaderstats.
local Add = 20
local Gun1 = player.Backpack.Steyr.StoredAmmo
local Gun2 = player.Backpack.Ak47.StoredAmmo
local Cost = 10
----------------------------------------------------------------------------------------------------
script.Parent.MouseButton1Click:connect(function()
print "Encounter"
if player.Backpack:FindFirstChild("Ak47")or player.Backpack:FindFirstChild("Steyr") then
if gold.value >=10 then
gold.value = gold.value - Cost
if player.Backpack:FindFirstChild("Ak47")then
Gun2.value = Gun2.value + Add
print "Purchase Complete : AK"

elseif player.Backpack:FindFirstChild("Steyr")then
Gun1.value = Gun1.value + Add
print "Purchase Complete : AUG"
end
end
end
end)



Who is dis? Dis is AuroJosh!
Report Abuse
AuroJosh is not online. AuroJosh
Joined: 04 Oct 2015
Total Posts: 484
30 Oct 2015 04:52 PM
You had a lot wrong in your script. I suggest doing more learning on if statements and

functions that start like this script.Parent.MouseButton1Click:connect(function ()



Who is dis? Dis is AuroJosh!
Report Abuse
cowsoncows is not online. cowsoncows
Joined: 11 Oct 2013
Total Posts: 2522
30 Oct 2015 04:57 PM
print("Encountered") --print function takes parentheses
print("Purchase Complete:AUG")
etc
Report Abuse
AuroJosh is not online. AuroJosh
Joined: 04 Oct 2015
Total Posts: 484
30 Oct 2015 04:59 PM
Yep, forgot that, thanks for pointing that out.

New code:

local player = script.Parent.Parent.Parent.Parent.Parent
local gold = player.leaderstats.MGR --Put your currency after Leaderstats.
local Add = 20
local Gun1 = player.Backpack.Steyr.StoredAmmo
local Gun2 = player.Backpack.Ak47.StoredAmmo
local Cost = 10
----------------------------------------------------------------------------------------------------
script.Parent.MouseButton1Click:connect(function()
print("Encounter")
if player.Backpack:FindFirstChild("Ak47")or player.Backpack:FindFirstChild("Steyr") then
if gold.value >=10 then
gold.value = gold.value - Cost
if player.Backpack:FindFirstChild("Ak47")then
Gun2.value = Gun2.value + Add
print("Purchase Complete : AK")

elseif player.Backpack:FindFirstChild("Steyr")then
Gun1.value = Gun1.value + Add
print("Purchase Complete : AUG")
end
end
end
end)



Who is dis? Dis is AuroJosh!
Report Abuse
tornadozebra is not online. tornadozebra
Joined: 02 Oct 2011
Total Posts: 316
30 Oct 2015 08:54 PM
My scripting is equal to that of a broken snow globe, so yeah...
Doesn't seem to work though...
Report Abuse
AuroJosh is not online. AuroJosh
Joined: 04 Oct 2015
Total Posts: 484
30 Oct 2015 09:03 PM
Can you add me so we can party each other?



Who is dis? Dis is AuroJosh!
Report Abuse
AuroJosh is not online. AuroJosh
Joined: 04 Oct 2015
Total Posts: 484
30 Oct 2015 09:04 PM
Found another thing. gold.value is suppose to be gold.Value

New code:

local player = script.Parent.Parent.Parent.Parent.Parent
local gold = player.leaderstats.MGR --Put your currency after Leaderstats.
local Add = 20
local Gun1 = player.Backpack.Steyr.StoredAmmo
local Gun2 = player.Backpack.Ak47.StoredAmmo
local Cost = 10
----------------------------------------------------------------------------------------------------
script.Parent.MouseButton1Click:connect(function()
print("Encounter")
if player.Backpack:FindFirstChild("Ak47")or player.Backpack:FindFirstChild("Steyr") then
if gold.Value >=10 then
gold.Value = gold.value - Cost
if player.Backpack:FindFirstChild("Ak47")then
Gun2.Value = Gun2.Value + Add
print("Purchase Complete : AK")

elseif player.Backpack:FindFirstChild("Steyr")then
Gun1.Value = Gun1.Value + Add
print("Purchase Complete : AUG")
end
end
end
end)



Who is dis? Dis is AuroJosh!
Report Abuse
AuroJosh is not online. AuroJosh
Joined: 04 Oct 2015
Total Posts: 484
30 Oct 2015 09:05 PM
Uhg this is annoying xD.

THIS SHOULD WORK

local player = script.Parent.Parent.Parent.Parent.Parent
local gold = player.leaderstats.MGR --Put your currency after Leaderstats.
local Add = 20
local Gun1 = player.Backpack.Steyr.StoredAmmo
local Gun2 = player.Backpack.Ak47.StoredAmmo
local Cost = 10
----------------------------------------------------------------------------------------------------
script.Parent.MouseButton1Click:connect(function()
print("Encounter")
if player.Backpack:FindFirstChild("Ak47")or player.Backpack:FindFirstChild("Steyr") then
if gold.Value >=10 then
gold.Value = gold.Value - Cost
if player.Backpack:FindFirstChild("Ak47")then
Gun2.Value = Gun2.Value + Add
print("Purchase Complete : AK")

elseif player.Backpack:FindFirstChild("Steyr")then
Gun1.Value = Gun1.Value + Add
print("Purchase Complete : AUG")
end
end
end
end)




Who is dis? Dis is AuroJosh!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • 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