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

Getting a coin once, why isn't it working?

Asked by 9 years ago

I've already asked this but the only answer I got was "Your script could be a lot simpler", so I'm asking it again (with an updated script).

You're supposed to get 1 coin for touching this coin, but you can't get it again. In a Script (Normal):

(EDITED SCRIPT)

game.Players.PlayerAdded:connect(function(player)
    got = false
    print("SET UP GOT VARIABLE")
    script.Parent.Touched:connect(function(part)
        if part.Parent.findFirstChild("Torso") ~= nil then
            print("PLAYER TOUCHED IT")
            if got == false then
            _G.Coins = _G.Coins + 1
            got = true
            print("PLAYER DOESN'T HAVE YET! GAVE PLAYER 1 COIN")
            part.Parent.Torso.CFrame = CFrame.new(Vector3.new(-16.1, 3, -219))
        end
        print("ENDING PLAYER CHECK")
    end
    print("ENDING SCRIPT!")
    end)
end)

Why doesn't it work? It doesn't even print the messages!

2 answers

Log in to vote
1
Answered by
Nexx 51
9 years ago

It should not be a localscript if the script is inside the workspace.

You need to modify it so that its a regular script.

Which also means you need to find other means to keep track if the user has gotten that coin or not.

0
Oh. Thanks. I don't know that much about LocalScripts. Also, I love your games Nexx! User#5565 45 — 9y
0
Edited it... Still doesn't work... User#5565 45 — 9y
0
Anything? User#5565 45 — 9y
0
... User#5565 45 — 9y
View all comments (2 more)
0
Nevermind! I solved the problem! User#5565 45 — 9y
0
Sorry! Rarely got on here! Would of helped out if I was. Nexx 51 — 9y
Ad
Log in to vote
0
Answered by
Merely 2122 Moderation Voter Community Moderator
9 years ago

On line, you're checking if the "got" variable is false, and it only gives out a coin if it's false. However, the first time the player touches the coin, it sets got to true. Since it is never set back to false, no more coins are awarded.

0
But itit increases _G.Coins by 1 BEFORE it sets got to true. User#5565 45 — 9y
0
It only increases _G.Coins the first time, because got is false. Merely 2122 — 9y
0
It is only supposed to give _G.Coins +1 once. Not once each touch, but once you get it you can't get it again. User#5565 45 — 9y
0
... User#5565 45 — 9y

Answer this question