while in roblox studio, the whole script works perfectly. but in an actual game, the script doesn't run at all. hierarchy: https://gyazo.com/2fdcb39db1d713a511931b0b106e4ec3

function deductMoney(stat, amount)
	stat.Value = stat.Value + amount
end

script.Parent.MouseButton1Click:connect(function()
	local stats = game.Players.LocalPlayer:findFirstChild("leaderstats")
    local bank = stats:findFirstChild("Bank") 
    local cash = stats:findFirstChild("Cash")
	local price = 20000
	if cash.Value >= price then
		deductMoney(cash, -price)
		local ak = game.ServerStorage["AK-47"]:Clone()
		local ak1 = game.ServerStorage["AK-47"]:Clone()
		ak.Parent = script.Parent.Parent.Parent.Parent.Parent.Parent.Backpack
		ak1.Parent = script.Parent.Parent.Parent.Parent.Parent.Parent.StarterGear
		script.Parent.Price.Text = "Purchased!"
 		game.Players.LocalPlayer.PlayerGui.GunShop.MainFrame.GunsFrame.ak47.LocalScript.Disabled = true
	elseif bank.Value >= price then
		deductMoney(bank, -price)
		local ak = game.ServerStorage["AK-47"]:Clone()
		local ak1 = game.ServerStorage["AK-47"]:Clone()
		ak.Parent = script.Parent.Parent.Parent.Parent.Parent.Parent.Backpack
		ak1.Parent = script.Parent.Parent.Parent.Parent.Parent.Parent.StarterGear
		script.Parent.Price.Text = "Purchased!"
 		game.Players.LocalPlayer.PlayerGui.GunShop.MainFrame.GunsFrame.ak47.LocalScript.Disabled = true
	else
		script.Parent.Price.Text = "Not enough funds!"	
		wait(3)
		script.Parent.Price.Text = "$20,000"	
		end
end)

4 comments

0

Is the game FilteringEnabled? If so, LocalScript's can't access ServerStorage.

0

good idea, but it's not FE, also my dialog shop works but not GUI

1

It does not have to be FilteringEnabled for a local script to not be able to access ServerStorage

0

Just figured that out and moved it to ReplicatedStorage. Thanks!