Help with Sell Gui

I try to make it work that when you click on the Button you can sell all your Clicks to Coins but it won’t work but there is also no error in the console

local Button = game.StarterGui.SellGui1.Frame.Sell1
Button.MouseButton1Click:Connect(function(HIT)
	local H = HIT.Parent:FindFirstChild("Humanoid")	
	if H then
		local player = game.Players:GetPlayerFromCharacter(HIT.Parent)	
if player then
	local leaderstats = player:WaitForChild("leaderstats")
	local Currency = leaderstats:WaitForChild("Coins") -- put the money of the leaderstats
	local Selling = leaderstats:WaitForChild("Clicks") -- put what you selling 
		if Selling.Value > 0 then
			Currency.Value = Currency.Value + Selling.Value
			Selling.Value = 0
		end
end
end
end)

Is there anything wrong with it?

It might be here.
Don’t try to access Sell1 through game.StarterGui. Rather, try to access through ancestry[ meaning script.Parent…]

Also, is that a server script?

  • Your variable button which uses the StarterGui not the player’s gui.
  • The callback function from MouseButon1Click does not fire any parameter, but it used to.

The only way for to be able to get the player is either; if the server script is parented to the GUI then just use script.Parent.Parent... or if it’s a local script you can simply use Players.LocalPlayer, or if the script is bind to the Players.PlayerAdded; Examples (this is just an example):

-- main function to call for each examples
local function Convert(leaderstats: Folder)
	if not leaderstats then
		return
	end

	do -- server script
		-- since this is a server script it would be simplier
		-- much and does not require any remote event

		-- you don't need to use any WaitForChild or
		-- FindFirstChild as this is a server script
		-- and can be trusted
		local coins: NumberValue = leaderstats.Coins
		local selling: NumberValue = leaderstats.Clicks

		if selling.Value > 0 then
			coins.Value += selling.Value
			selling.Value = 0
		end
	end

	do -- client script
		-- you need a remote even for this one and the reciever's
		-- function(server script) is similar to the code block above
		RemoteEvent:Fire()
	end
end
Server script parented to the ScreenGui
local player: Player = script.Parent.Parent.Parent
local button: GuiButton = script.Parent.Button
local leaderstats: Folder = player:WaitForChild("leaderstats")

button.MouseButtonClick:Connect(function()
	Convert(leaderstats)
end)
Client script either parented to the ScreenGui
-- can also be parented to the PlayerScripts, but
-- you would have to modify the script a little

local player = game:GetService("Players").LocalPlayer
local button: GuiButton = script.Parent.Button
local leaderstats: Folder = player:WaitForChild("leaderstats")

button.MouseButtonClick:Connect(function()
	Convert(leaderstats)
end)
Server script bind to the PlayerScripts
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	-- after every instance created and get data from DataStore

	-- while this depends on the ScreenGui if the ResetOnRespawn is disabled
	local button: GuiButton = player.PlayerGui:WaitForChild(--[[ name of the gui ]]).Button

	button.MouseButton1Click:Connect(function()
		Convert(leaderstats)
	end)
end)