I’m trying to make a shop system. The code shown below is the buy script. It’s supposed to change the value of a boolean value in a gui. When I test it the boolean value doesn’t change to true. No errors are coming up
local Cost = 100
local player = game.Players.LocalPlayer
local playerStats = player:WaitForChild("leaderstats")
local playerGold = playerStats:WaitForChild("Gold")
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local Owned = gui.Shop.Stats.Frame.LongStick.Owned.Value
script.Parent.MouseButton1Click:Connect(function()
if playerGold.Value >= Cost and Owned == false then
playerGold.Value = playerGold.Value - Cost
Owned = true
end
end)
local player = game.Players.LocalPlayer
local playerStats = player:WaitForChild("leaderstats")
local playerGold = playerStats:WaitForChild("Gold")
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local Owned = gui.Shop.Stats.Frame.LongStick.Owned
script.Parent.MouseButton1Click:Connect(function()
print("Button clicked!")
if playerGold.Value >= Cost and Owned == false then
playerGold.Value = playerGold.Value - Cost
Owned.Value = true
else
print("Not enough gold!")
end
end)
Edit: Updated script with some @Wizard101fire90 of his script
local Cost = 100
local player = game.Players.LocalPlayer
local playerStats = player:WaitForChild("leaderstats")
local playerGold = playerStats:WaitForChild("Gold")
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local Owned = gui.Shop.Stats.Frame.LongStick.Owned.Value = false
script.Parent.MouseButton1Click:Connect(function()
if playerGold.Value >= Cost and Owned == false then
playerGold.Value = playerGold.Value - Cost
Owned = true
end
end)
local Cost = 100
local player = game.Players.LocalPlayer
local playerStats = player:WaitForChild("leaderstats")
local playerGold = playerStats:WaitForChild("Gold")
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local Owned = gui.Shop.Stats.Frame.LongStick.Owned
Owned.Value = false
script.Parent.MouseButton1Click:Connect(function()
if playerGold.Value >= Cost and Owned == false then
playerGold.Value = playerGold.Value - Cost
Owned.Value = true
end
end)
local Cost = 100
local player = game.Players.LocalPlayer
local playerStats = player:WaitForChild("leaderstats")
local playerGold = playerStats:WaitForChild("Gold")
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local Owned = gui.Shop.Stats.Frame.LongStick.Owned
Owned.Value = false
script.Parent.MouseButton1Click:Connect(function()
if playerGold.Value >= Cost and Owned == false then
playerGold.Value = playerGold.Value - Cost
Owned.Value = true
else
print("Not Enough Gold")
end
end)
It said that I didn’t have enough money when I clearly did because I had 1 million, I then added this instead
local Cost = 100
local player = game.Players.LocalPlayer
local playerStats = player:WaitForChild("leaderstats")
local playerGold = playerStats:WaitForChild("Gold")
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local Owned = gui.Shop.Stats.Frame.LongStick.Owned
Owned.Value = false
script.Parent.MouseButton1Click:Connect(function()
if playerGold.Value >= Cost and Owned == false then
playerGold.Value = playerGold.Value - Cost
Owned.Value = true
else if playerGold.Value < Cost then
print("Not Enough Gold")
end
end
end)
It didn’t say anything in the outputs so something else isn’t working.
local Players = game:GetService("Players");
local COST = 100;
local DEBUG = true;
local goldValue = Players.LocalPlayer
:WaitForChild("leaderstats")
:WaitForChild("Gold");
-- Property access nightmare.
local ownedValue = Players.LocalPlayer
:WaitForChild("PlayerGui")
:WaitForChild("ScreenGui")
.Shop
.Stats
.Frame
.LongStick
.Owned;
ownedValue.Value = false;
local function onClick()
if goldValue.Value >= COST and not ownedValue.Value then
goldValue.Value = goldValue.Value - COST;
ownedValue.Value = true;
if DEBUG then
print("The item was purchased");
end
elseif DEBUG then
if goldValue.Value < COST then
local message = ("Not enough gold! Player has '%d' but needs '%d'"):format(
goldValue.Value,
COST
);
print(message);
end
if ownedValue.Value then
print("Item is already owned!");
end
end
end
script.Parent.MouseButton1Click:Connect(onClick);