|
| 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
|
  |
| Joined: 28 Mar 2013 |
| Total Posts: 322 |
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 30 Oct 2015 04:57 PM |
print("Encountered") --print function takes parentheses print("Purchase Complete:AUG") etc |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|