Made a gui click to buy shop but it doesn't work

I made a script that when you click a textbutton player will be granted a tool from Lighting.
Don’t know where the script had went wrong.
The textbutton includes the number value of the tool name in Lighting and the cost value and the currency (Garri).
Any help is appreciated.

(Note: the value is not a leaderstats value, but just a stats value stored in data.)

The buy script:

script.Parent.Text="Cut Fist"..": "..tonumber(script.Parent.Cost.Value).." "..tostring(script.Parent.Currency.Value)

script.Parent.MouseButton1Click:connect(function()

if game.Players.LocalPlayer:findFirstChild("stats") then

if game.Players.LocalPlayer.Data.Garri.Value>=0 then

game.Players.LocalPlayer.Data.Garri.Value=game.Players.LocalPlayer.Data.Garri.Value-0

game.Lighting[script.Parent.ItemName.Value]:Clone().Parent=game.Players.LocalPlayer.Backpack

game.Lighting[script.Parent.ItemName.Value]:Clone().Parent=game.Players.LocalPlayer.StarterGear

end

end

end)

The “Garri” data:
image

Try using server storage instead.

I suggest using leaderstats instead of some value

(Also, are there any errors in the output?)

Does the button do anything once it’s clicked? Try printing something to see if the button is actually working. If the button is not interact-able, make sure it has ‘Selectable’ set to true and ‘Active’ as true. If the button does print something:

  • Does ‘stats’ exist in the Player?
  • Does the tool exist in Lighting?

Also I would recommend using remote events and sending a message to the server to indicate these checks as exploiters could clone the tools directly from Lighting and change the value of their currency locally.

the tool is in lighting.
all the stats are in a separate data script in serverscriptsservice, and they are completely fine.

  1. Replace the buy LocalScript with this:
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local remoteEvent = replicatedStorage:WaitForChild("giveGear")
local self = players.LocalPlayer

script.Parent.Text = string.format("Cut Fist: %s %s",
	tonumber(script.Parent.Cost.Value, tostring(script.Parent.Currency.Value))
)

script.Parent.MouseButton1Click:Connect(function()
	if not self:FindFirstChild("stats") or not self:FindFirstChild("Data") then return end
	if not self.Data:FindFirstChild("Garri") then return end
	
	if self.Data.Garri.Value >= script.Parent.Cost.Value then
		remoteEvent:FireServer(script.Parent.ItemName.Value)
	end
end)
  1. Insert a RemoteEvent in ReplicatedStorage named giveGear
  2. Move the gear you want to give into ReplicatedStorage.
  3. Script in ServerScriptService with this code:
local replicatedStorage = game:GetService("ReplicatedStorage")

local price = 100 -- Change price to what the cost of that gear is

replicatedStorage.giveGear.OnServerEvent:Connect(function(self, gear)
	local gear = replicatedStorage[gear]
	if not gear then return end
	
	if self.Data.Garri.Value >= price then
		self.Data.Garri.Value -= price
		gear:Clone().Parent = self.Backpack
		gear:Clone().Parent = self.StarterGear
	else
		self:Kick("Exploiting. \n\n RemoteEvent Manipulation. \n")
	end
end)

Also I noticed that you could get the gear without losing any “Garri”. If this was for testing purposes then you can revert some of my changes.

I also have a knack for naming the player variable self.:skull:

1 Like

Thanks! It still didn’t work, it must’ve been the value errors, I will check