Can someone help script a Coin that gives points?

Pretty much I want a Coin that will give points on the leaderstat. Make sure the script is compatible with local scripts.

I found this tutorial that might help you

Put this script in the ServerScriptService

local function onPlayerJoin(player)
    --Create the leaderstats folder
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    --Create the coins number value
    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Value = 0
    coins.Parent = leaderstats
end

game.Players.PlayerAdded:Connect(onPlayerJoin)

Then a script that you put in the hitbox of the coin

--When the part gets touched
script.Parent.Touched:Connect(function(hit)
    --Check if the toucher is actually a player
	local plr = game.Players:FindFirstChild(hit.Parent.Name)
	if plr then
       --Add 1 coin to the player stats
		plr.leaderstats.Coins.Value += 1
        --Delete the coin
        script.Parent.Parent:Destroy()
	end
end)

This should add 1 coin to the player that touches the coin

3 Likes

kasjmirr already answered your question but what do you mean “compatible with local scripts”

You can only change the leaderstats with a normal script, so it can’t be “compatible with local scripts”

Do you mean collect coins on the client or more responsive coins. You can always add an extra localscript to hide the coin on touch:

script.Parent.Touched:Connect(function(plr)
	if plr.Parent == game.Players.LocalPlayer.Character then
		script.Parent.Transparency = 1
	end
end)

Place a Server Script into the coin with this, and set RunContext to Client.

I made this on mobile