local T=EventsFolder:FindFirstChild("\078\111\116\105\102\105\099\097\116\105\111\110")local G=EventsFolder:FindFirstChild("\069\100\105\116\080\108\111\116")local o=game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")local H=script.Parent.Parent.Parent.Parent.SignDescription.SurfaceGui.Frame.OwnerLabel local y=game:GetService("\083\116\097\114\116\101\114\071\117\105")local R=script.Parent.Parent.Parent.Parent.Name local f=y:FindFirstChild("\083\105\103\110\080\114\105\099\101\115")local N=f:WaitForChild(R)local j=N.ScrollingFrame:FindFirstChild("\084\101\109\112\108\097\116\101")function Triggered(o)local y=o.Name if Owner.Value==nil or"\078\111\079\110\101"then if o:FindFirstChild("\079\119\110\101\114")then T:FireClient(o,"\067\108\097\105\109\101\100")else Owner.Value=y H.Text=y.."\'\115 \083\116\097\110\100"T:FireClient(o,true)local R=(game:GetService("\080\108\097\121\101\114\115")):GetUserIdFromNameAsync(y)Bindable:Fire(script.Parent.Parent.Parent.Parent.Name,y,R)H.Parent.MoneyRaised.Text=o.leaderstats.Raised.Value.."\036 \082\097\105\115\101\100"local f=Instance.new("\073\110\116\086\097\108\117\101")f.Value=script.Parent.Parent.Parent.Parent.Name f.Name="\079\119\110\101\114"f.Parent=o G:FireClient(o,script.Parent.Parent.Parent.Parent.Name,true)Prompt.Enabled=false end end end script.Parent.Triggered:Connect(Triggered)local v=game:GetService("\080\108\097\121\101\114\115")local V=EventsFolder:FindFirstChild("\082\101\109\111\118\101\066\117\116\116\111\110\070\114\111\109\067\108\105\101\110\116")v.PlayerRemoving:Connect(function(T)local o=T.Name if o==Owner.Value then V:FireAllClients(script.Parent.Parent.Parent.Parent.Name)Owner.Value="\078\111\079\110\101"G:FireClient(T,script.Parent.Parent.Parent.Parent.Name,false)Prompt.Enabled=true H.Text="\078\111 \079\110\101\'\115 \083\116\097\110\100"script.Parent.Parent.Parent.Parent.SignTitle.SurfaceGui.Frame.SignLabel.Text="\080\076\083 \068\079\078\065\084\069"H.Parent.MoneyRaised.Text="\048\036 \082\097\105\115\101\100"local o=y.SignPrices[script.Parent.Parent.Parent.Parent.Name].ScrollingFrame:GetChildren()for T,G in ipairs(o)do if G:IsA("\070\114\097\109\101")and G.Name~="\084\101\109\112\108\097\116\101"then G:Destroy()end end else return end end)

local Notification = EventsFolder:FindFirstChild("Notification")
local EditPlot = EventsFolder:FindFirstChild("EditPlot")

local MarketPlaceService = game:GetService("MarketplaceService")

local OwnerLabel = script.Parent.Parent.Parent.Parent.SignDescription.SurfaceGui.Frame.OwnerLabel

local StarterGui = game:GetService("StarterGui")
local StandNum = script.Parent.Parent.Parent.Parent.Name

local PriceFolder = StarterGui:FindFirstChild("SignPrices")
local UI = PriceFolder:WaitForChild(StandNum)

local Template = UI.ScrollingFrame:FindFirstChild("Template")


function Triggered(Player)

	local PlayerName = Player.Name

	if Owner.Value == nil or "NoOne" then -- If booth hasn't been claimed
		if Player:FindFirstChild("Owner") then  -- If Player has claimed one
			Notification:FireClient(Player,"Claimed") -- Let them know they already own one
		else -- If Player hasn't claimed one
			Owner.Value = PlayerName
			OwnerLabel.Text = PlayerName .. "'s Stand"
			Notification:FireClient(Player,true) -- Claimed

			local UserID = game:GetService("Players"):GetUserIdFromNameAsync(PlayerName)
			Bindable:Fire(script.Parent.Parent.Parent.Parent.Name, PlayerName, UserID)

			-- This should be for giving a player a value
			OwnerLabel.Parent.MoneyRaised.Text = Player.leaderstats.Raised.Value .. "$ Raised"

			local OwnerValue = Instance.new("IntValue")
			OwnerValue.Value = script.Parent.Parent.Parent.Parent.Name -- set int value to booth name
			OwnerValue.Name = "Owner"
			OwnerValue.Parent = Player

			-- Would this be the best way to do this? Yes, absolutely!

			-- We want the editPrompt to ONLY show for the client player.

			EditPlot:FireClient(Player, script.Parent.Parent.Parent.Parent.Name, true)
			Prompt.Enabled = false
		end
	end	
end

script.Parent.Triggered:Connect(Triggered)


local Players = game:GetService("Players")
local RemoveButtonsFromClient = EventsFolder:FindFirstChild("RemoveButtonFromClient")

Players.PlayerRemoving:Connect(function(player)
	local plrRemovingName = player.Name
	if plrRemovingName == Owner.Value then
		RemoveButtonsFromClient:FireAllClients(script.Parent.Parent.Parent.Parent.Name)
		Owner.Value = "NoOne"
		EditPlot:FireClient(player, script.Parent.Parent.Parent.Parent.Name, false)
		Prompt.Enabled = true

		OwnerLabel.Text = "No One's Stand"
		script.Parent.Parent.Parent.Parent.SignTitle.SurfaceGui.Frame.SignLabel.Text = "PLS DONATE"
		OwnerLabel.Parent.MoneyRaised.Text = "0$ Raised"

		local Children = StarterGui.SignPrices[script.Parent.Parent.Parent.Parent.Name].ScrollingFrame:GetChildren()
		for _, child in ipairs(Children) do
			if child:IsA("Frame") and child.Name ~= "Template" then
				child:Destroy()
			end
		end
	else
		return -- Not the Owner
	end
end)
