Hello again!
I am currently coding the purchase button that should give a food tool when successfully purchased, but whenever I click to purchase it doesn’t give me the tool, nor does it give me an error message or even take away the price from my cash leaderstat. Can anyone help me? Here are my scripts:
LocalScript:
local button = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local upgradeBought = replicatedStorage:WaitForChild("remoteEvents").upgradeBought
local price = 50
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
button.MouseButton1Up:Connect(function()
local cash = leaderstats:WaitForChild("Cash")
if cash.Value >= price then
upgradeBought:FindFirstChild(price)
end
end)
Script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local upgradeBought = replicatedStorage:WaitForChild("remoteEvents").upgradeBought
upgradeBought.OnServerEvent:Connect(function(player, price)
local leaderstats = player:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Cash")
if cash.Value >= price then
cash.Value = cash.Value - price
local food = replicatedStorage:WaitForChild("food"):Clone()
food.Parent = player.Backpack
end
end)