when player clicks the button it should take the price out of the tokens
---/// locals
local PurchaseItem = game.ReplicatedStorage.Events.PurchaseItem
local PurchaseButton = script.Parent
local PricesFolder = script.Parent.Parent.Parent.Parent.Prices
local Item = PricesFolder.Speed
local Price = Item.Value
local player = game.Players.LocalPlayer
PurchaseButton.MouseButton1Click:Connect(function(plr)
if player.leaderstats.Tokens.Value >= Price then
player.leaderstats.Tokens.Value = player.leaderstats.Tokens.Value - Price
end
end)
This won’t work because you are trying to do this locally.
You need to fire a remote event to the server and make the purchase there.
Create a remote event and place it in ReplicatedService
local script
PurchaseButton.MouseButton1Click:Connect(function(plr)
if player.leaderstats.Tokens.Value >= Price then
game.ReplicatedStorage.BuySomething:Fire()
end
end)
Server script:
game.ReplicatedStorage.BuySomething.OnServerEvent:Connect(function(player)
if player.leaderstats.Tokens.Value >= Price then
player.leaderstats.Tokens.Value = player.leaderstats.Tokens.Value - Price
end
end)
I typed this out quick so I may have made a mistake