Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

6 comments

0

Oh. Thanks. I don't know that much about LocalScripts. Also, I love your games Nexx!

0

Edited it... Still doesn't work...

0

Anything?

0

...

0

Nevermind! I solved the problem!

0

Sorry! Rarely got on here! Would of helped out if I was.

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.

4 comments

0

But itit increases _G.Coins by 1 BEFORE it sets got to true.

0

It only increases _G.Coins the first time, because got is false.

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.

0

...

This discussion is preserved as it was. New answers, comments, and votes are closed.