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))

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!