Trying to make a coin give the player 1, instead it gives multiples of 1

As the title states, I want my coin to add 1 to the leaderboard, but for some reason it gives the player a number which is a multiple of 1.

image

(keep in mind I’m very new to scripting, and this is half a tutorial and half my own work)

1 Like

When the Coinpart.Touched, disable the Coinpart.CanTouch before giving the 1 coin.

Coinpart.CanTouch = false
1 Like

Doesn’t seem to work. What I did for reference incase I formatted anything incorrectly (although I’m getting no errors)

	Coinpart.Touched:Connect(function(PartTouched)
		if PartTouched.Parent:FindFirstChild("Humanoid")then 
			Coinpart.CanTouch = false
			Coins.Value = Coins.Value +1
			Coinpart:Destroy()
		end
	end)

then add a debounce for the script

local debounce = false -- put this line outside the player.PlayerAdded event
Coinpart.Touched:Connect(function(PartTouched)
	if debounce then return end
	debounce = true
	if PartTouched.Parent:FindFirstChild("Humanoid") then 
		Coinpart.CanTouch = false
		Coins.Value = Coins.Value +1
		Coinpart:Destroy()
	end
end)

Yes, thank you this does work, kind of. For example: I pick up the coin and it disappears, reload the game but then when I collide nothing happens. There seems to be some correlation for it working when I specifically leave by pressing Esc then pressing the leave button. It also doesn’t work the first time I join the actual Roblox game.

So something that is not a player character is touching the part before the player character, also enable the CanTouch if you are going to clone the part:

local debounce = false -- put this line outside the player.PlayerAdded event
Coinpart.Touched:Connect(function(PartTouched)
	if debounce then return end
	if PartTouched.Parent:FindFirstChild("Humanoid") then 
		debounce = true
		Coinpart.CanTouch = false
		Coins.Value = Coins.Value +1
		Coinpart:Destroy()
	end
end)
1 Like

Sorry if it’s too much trouble, but although it’s working now with one coin, if there is multiple coins on the map it only gives +1 for a singular coin. I’ve tried everything from playing around with CanTouch to playing around with the debounces and not a singular thing has worked. The coins all still destroy themselves, just don’t give any currency. In the end the script is still exactly the same as the one you suggested.

You just need to move the function outside the Player.PlayerAdded, this happens because the function only works when the player is added, which explains why it happens once.

It gives the error attempt to index nil with ‘Value’, and shows a blue underline beneath Coin.Value
image

When your part is touched, you have the touchedpart and this can lead to the player character you can use it to get the player and get the Coins leaderstats from the player.

1 Like

Thank you! Took me a bit but finally got it to work.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.