I'm trying to make it so when you touch a gold coin you'll get 25 points/coins. But it only works on studio. Help me please, also give me tips with scripting things for studio and outside of studio.

children = game.Workspace.Coins:GetChildren()
while true do
	for _, child in ipairs(children) do
		if child.Name == "GoldCoin" then
			child.Touched:connect(function(Touched)
			local p = Touched.Parent:FindFirstChild("Humanoid")
			if p ~= nil then
		    local player = game.Players:GetPlayerFromCharacter(Touched.Parent)
	        player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 25
			Sound = script.CoinSound:Clone()
			Sound.Parent = child
			Sound:Play()
		    game.Debris:AddItem(Sound, 7)
			child:remove()
			end			
			end)
		end
	end
	wait()
end

2 comments

0

One note, never ever ever ever ever use :remove(), only ever :destroy() (Unless you want to be able to re-parent the instance). Remove does NOT delete the object from the game, just sets it's parent to nil.

0

Destroy also set the Parent to nil but however the only real difference between destroy and remove is that destroy locks the Parent property while remove sets it to nil.