How do I debug this button script that activates a boolean value in the workspace

This script shown here is a ServerScript.

local TGui = script.Parent.Parent.Parent
local SGui = script.Parent.Parent
local Button = SGui:WaitForChild("AsgoreButton")
local PlayerService = game:GetService("Players")
local debounce = false
local bool = workspace.SansNAsgore
local badgeService = game:GetService("BadgeService")
local badge = 1717683932853397

local function playerClicked(Player)
	print("STATE 1 COMPLETE")
	if badgeService:UserHasBadgeAsync(Player,badge) then
		bool = true
		print("STATE 2 COMPLETE")
		TGui:Destroy()
	end
end

Button.ClickDetector.MouseClick:Connect(playerClicked(PlayerService))

535bbd3fae23dc1f5fd8930f733e5e95

For context, I’m trying to make it so that when a player clicks on the button, the script will activate the boolean value and then change the map, give the Sans team a whole new set of attacks and destroy the entire GUI for that team. (This is a Sans vs Chara game so when the player chooses another “Sans character” through the GUI, the game will change the map, replace the models however I think I can do that for the server to see) However, I already encounter multiple issues including the first one.

Unable to cast Instance to int64 
Stack Begin  -  Studio
Script 'Players.borenreef.PlayerGui.OtherSansGui.Frame.AsgoreButton.Script', Line 12 - function playerClicked  -  Studio - Script:12
Script'Players.borenreef.PlayerGui.OtherSansGui.Frame.AsgoreButton.Script', Line 19  -  Studio - Script:19
Stack End

Not only that, I don’t know if this is the most efficient way to do this. I need help knowing if I should use a LocalScript for this or a ServerScript for doing what I said above the error line. I’d appreciate the help!

local TGui = script.Parent.Parent.Parent
local SGui = script.Parent.Parent
local Button = SGui:WaitForChild("AsgoreButton")
local PlayerService = game:GetService("Players")
local debounce = false
local bool = workspace.SansNAsgore
local badgeService = game:GetService("BadgeService")
local badge = 1717683932853397

local function playerClicked(Player)
	print("STATE 1 COMPLETE")
	if badgeService:UserHasBadgeAsync(Player,badge) then
		bool = true
		print("STATE 2 COMPLETE")
		TGui:Destroy()
	end
end

Button.ClickDetector.MouseClick:Connect(playerClicked)

Forget what I said, that’s not the case. Most of the code was copied from a YouTube click script.

I copied the script and the boolean value in workspace does not change at all. Nor does it print any of the print()s in the function I made. Is there a issue in the code?

local TGui = script.Parent.Parent.Parent
local SGui = script.Parent.Parent
local Button = SGui:WaitForChild("AsgoreButton")
local PlayerService = game:GetService("Players")
local debounce = false
local bool = workspace.SansNAsgore
local badgeService = game:GetService("BadgeService")
local badge = 1717683932853397

local function playerClicked(Player)
	print("STATE 1 COMPLETE")
	if badgeService:UserHasBadgeAsync(Player,badge) then
		bool.Value = true
		print("STATE 2 COMPLETE")
		TGui:Destroy()
	end
end

Button.ClickDetector.MouseClick:Connect(playerClicked)

It appears Bool is a BooleanValue.

I’ve almost forgot to mention this, I changed the script into a LocalScript in order for a RemoteEvent to run. This is the new script.

Open to see the LocalScript
local TGui = script.Parent.Parent.Parent
local SGui = script.Parent.Parent
local Button = SGui:WaitForChild("AsgoreButton")
local PlayerService = game:GetService("Players")
local Player = game.Players.LocalPlayer
local bool = workspace.SansNAsgore
local badgeService = game:GetService("BadgeService")
local badge = 1717683932853397
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.SansChangerEvent

Button.MouseButton1Click:Connect(function(Player)
	print("STATE 1 COMPLETE")
	if badgeService:UserHasBadgeAsync(Player,badge) then
		bool.Value = true
		print("STATE 2 COMPLETE")
		TGui:Destroy()
		remoteEvent:FireServer()
	end
end)

Now for context, I’m trying to make it so that the LocalScript fires off a RemoteEvent to the 2nd script in ServerScriptService called SansChanger.

Here is the server script for it.

Open to see the ServerScript
local function AsgoreMode()
	if bool1 == true then
		OGSans:Destroy()
		SansNAsgore:Clone()
		SansNAsgore.Parent = workspace
		music:Stop()
		music2:Play()
	end
end

remoteEvent.OnServerEvent:Connect(AsgoreMode)

This is just a snippet of the code.

However, I want to get into the real issues instead before I get into the server script. I’m sorry if it seems too demanding, I just want to make sure both scripts work together.

This is the main script I want to focus on.

While I do recongize I was supposed to put bool.Value = true, and that print("STATE 1 COMPLETE") now appears, there’s another issue and there is a 2nd error.

Players.borenreef.PlayerGui.OtherSansGui.Frame.AsgoreButton.ClickScript:14: attempt to index nil with 'UserId'  -  Client - ClickScript:14
  Stack Begin  -  Studio
  Script 'Players.borenreef.PlayerGui.OtherSansGui.Frame.AsgoreButton.ClickScript', Line 14  -  Studio - ClickScript:14
 Stack End

I don’t know what is wrong that has to do with UserHasBadgeAsync(Player,badge) because I’m pretty sure I wrote most things well, unless I am exaggerating heavily on the details. If there is something wrong with that part, what am I supposed to write?

I apologize for the inconvience I made cause with changing the scripts.

Update: I removed Player.UserId and put Player instead for the UserHasBadgeAsync and now it shows Argument 1 missing or nil for the same line.