Shop gui help with script

local player = script:FindFirstAncestorOfClass("Player")


function Click(mouse)
if player.leaderstats.Money.Value >= 390 then
	player.leaderstats.Money.Value = player.leaderstats.Money.Value - 390
	local tool = game.Lighting.BoomBox:Clone()
	wait(0.1)
	tool.Parent = player.Backpack
	local new = Instance.new("StringValue", game.Lighting.ToolManager.BoomboxNames)
	new.Name = player.Name
	new.Value = player.Name
	wait(0.1)
	script:Destroy()
else
	print("Nothing")
end
end

script.Parent.MouseButton1Down:connect(Click)

This script is meant to check if the Value has a number higher than 390 but it fails to work, what do I do?

It is not a local script, it’s a normal script

Fails to work how? Throwing a block of code and saying it doesn’t work isn’t helpful to those who are looking through the thread and want to offer a potential fix.

Also, don’t handle Guis through a normal script, that’s bad practice. Use a LocalScript to handle the Gui and leave important interactions (giving of tool and subtraction of money) to the server. Use a remote to bridge this action.

local player = script:FindFirstAncestorOfClass(“Player”)
Turn this into a local script

Use

local player = game:GetService('Players').LocalPlayer

Send a remote fire to handle the purchase on the server
https://developer.roblox.com/articles/Remote-Functions-and-Events (page currently down but for future reference)
https://developer.roblox.com/api-reference/class/RemoteEvent

The idea is if the player has enough cash on their leaderstats it gives them the tools, but it is saying they don’t have enough money, if I changed the leaderstats during a test play would it work?

You’re most likely changing it on the client which won’t replicate then

1 Like

Okay, I’ll test this on a live server, I’ll tell you whether or not this works.

No, that’s not the problem. It’s that you’re handling the Gui wrong. You shouldn’t use a server script for any kind of interface. A fundamental problem is your implementation itself and you should fix that before you go on to try and debug the problem, which is a product of the bad code structure in the first place.