Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gun Purchase script is not working?

Asked by 10 years ago
01player = script.Parent.Parent.Parent.Parent.Parent
02cost = 500
03 
04function checkForColt()
05    found = false
06    for i, v in pairs(player.Backpack:GetChildren()) do
07        if v.Name == "Colt" then
08            found = true
09        end
10    end
11    for i, v in pairs(player.Charater:GetChildren()) do
12        if v.Name == "Colt" then
13            found = true
14        end
15    end
View all 39 lines...

My leaderboard stats work fine, it out put's no errors and the colt is correctly labeled. 10+ cookiez to the guy the works it out.

0
Try using two variables instead of just one called found. It can be overwritten by the second do loop which could cause the checking for Colt to not go as planned. Also, I believe you might be using your function checkForColt() wrong by making it a variable. Instead on line 29, just call the function by doing only `checkForColt()` . Then on line 30, after "and", check your *two* new variables. alphawolvess 1784 — 10y

2 answers

Log in to vote
0
Answered by
davness 376 Moderation Voter
10 years ago

You comitted several errors:

01player = game.Players.LocalPlayer -- LocalPlayer, LocalScript!
02cost = 500
03 
04function checkForColt()
05    found = false
06    for i, v in pairs(player.Backpack:GetChildren()) do
07        if v.Name == "Colt" then
08            found = true
09        end
10    end
11    for i, v in pairs(player.Charater:GetChildren()) do
12        if v.Name == "Colt" then
13            found = true
14        end
15    end
View all 39 lines...

Well, i'm not a proscripter. But try to put it inside a LocalScript instead of a normal one (I guess you used the normal one) - Do not get mad if it do not work. I tryed at least.

0
If it's in a GUI, it should be a LocalScript. Also, LocalScripts don't work for ServerStorage, but they do work for ReplicatedStrorage. alphawolvess 1784 — 10y
0
I have just noticed in the leaderstats I have money rather than points XD WolfgangVonPrinz 0 — 10y
0
Wolfgang, i need the hierachy of the game where the script is davness 376 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
01player = game.Players.LocalPlayer
02 
03cost = 500
04 
05 
06 
07function checkForColt()
08 
09    found = false
10 
11    for i, v in pairs(player.Backpack:GetChildren()) do
12 
13        if v.Name == "Colt" then
14 
15            found = true
View all 69 lines...

So, I've re-written, but it read's errors I don't know how to solve.

"Charater is not a valid member of player." I tried Humanoid too, but no luck. Those cookies are still up for grabs!

Answer this question