Need help with coin collection system

so i’m working on a project. the player has a vacuum and when it is equipped, they are then able to step over coins, which adds to the “Coins” Value in their leaderstats. the leaderbord itself works, but the coin collection system doesn’t. below are the scripts.


game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	
	local Coins = Instance.new("IntValue",leaderstats)
	Coins.Name = "Coins"
end)

here is my tool script: ( there is a remote event in the script).

this script is a local script btw.


script.Parent.Equipped:Connect(function()
	script.Parent.RemoteEvent:FireServer()
end)

and here is a server script, which is supposed to make it so when the remote event is fired, they can walk over the coin and it adds to the leaderstats.

game.StarterPack.Vacuum.RemoteEvent.OnServerEvent:Connect(function(player)
	script.Parent.Touched:Connect(function(hit)
		if game.Players:GetPlayerFromCharacter(hit.Parent)then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
		end
	end)
end)

thanks for reading.

The issue with your issue is how the system is made in the first place from the looks of it via the organization of it

Here’s how I would recommend the system to be made for your vacuum

  • Setup variables for the character and the player in a regular script in the yacuum

  • Make it so when the main part of the Vacuum is touched, it checks to see if the thing that touched it was a coin, and it if it was, destroy the coin and award the player a coin in their Coins leaderstats.

You can get the Character of the palyer holding the vacuum via getting the tool’s parent when equipped and the player via GetPlayerFromCharacter

1 Like