Coin pickups with owner only system to spawn them

So i have recently made this system, with coins that add up to tally on leaderboard and i’m the only one who can spawn them.
My question would be, how can this code be improved and what general tips would there be.
I had help with only one part of this system, which would be visibility of menu that opens the coin spawn
All visibiliy scripts are LocalScripts, while everything else is in usual script.
Credit to devforum member for GUI visibility script: Awesom3_Eric
GUI visibility script:

local Players = game:GetService("Players")
local player = Players.LocalPlayer 

local button = script.Parent
if player.UserId ~= game.CreatorId then 
	button:Destroy()
end

Visibility script for coin spawner buttons:

local visible = false
local activator = script.Parent.Parent.OpenButton
local button = script.Parent

local function buttonActivation()
	if (visible == false) then
		button.Visible = false
	elseif (visible ~= false) then
		button.Visible = true
	end
	if activator.MouseButton1Click and (visible == false) then
		visible = true
	elseif activator.MouseButton1Click then
		visible = false
		
	end
end
activator.MouseButton1Click:Connect(buttonActivation)

Script for actual coin spawning:

local button = script.Parent
local coin = game.ReplicatedStorage.Coins.SilverCoin
local function buttonActivated()
	if button.MouseButton1Click then
		local ClonedCoin = coin:Clone()
		ClonedCoin.Parent = game.Workspace
		ClonedCoin:SetPrimaryPartCFrame(CFrame.new(0, 50, 0))
	end
end
button.MouseButton1Click:Connect(buttonActivated)

Script for the coins themselves:

local Players = game:GetService("Players")

local coin = script.Parent

local function onPartTouch(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		
		coin:Destroy()
		
		local player = Players:GetPlayerFromCharacter(partParent)
		local leaderstats = player.leaderstats
		local coinsStat = leaderstats and leaderstats:FindFirstChild("Coins")
		if coinsStat then
			coinsStat.Value = coinsStat.Value + 10
		end
	end
end
coin.Touched:Connect(onPartTouch)

why not make this better?

button.Visible = visible

if activator.MouseButton1Click then
    visible = not visible
end 

You see, i want the GUI to be able to be hidden or shown to me whenever i please, even when i adjusted your iteration to this:

local visible = false
local activator = script.Parent.Parent.OpenButton
local button = script.Parent

button.Visible = visible

if activator.MouseButton1Click then
	visible = not visible
end 
activator.MouseButton1Click:Connect()

it still breaks the entire sequence

local visible = false
local activator = script.Parent.Parent.OpenButton
local button = script.Parent

local function buttonActivation()
    button.Visible = visible

    if activator.MouseButton1Click then
        visible = not visible
    end
end

activator.MouseButton1Click:Connect(buttonActivation)

what are you doing :joy:
when did I tell you to remove the function
@realknife

That worked, it just so happened that it was in the morning, which is the time i’m known for not thinking straight.

local partParent = otherPart.Parent
local player = Players:GetPlayerFromCharacter(partParent)

if player then
    coin:Destroy()

    local leaderstats = player.leaderstats
    local coinsStat = leaderstats and leaderstats:FindFirstChild("Coins")

    if coinsStat then
        coinsStat.Value += 10
    end
end

one last thing, but why define the humanoid and the player?
just define the player and check if the player exists