Purchase Button does not work

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)

I think you meant to say FireServer!

Another concern I have, why is the client telling the server the price? Shouldn’t the server be telling the client that?

The client just sends the price to the server so that the server can take that away from the leaderstat value, as far as I know, if you do it in a client script it will not actually change in the server, meaning it would not save properly.

But the server should know the price, it shouldn’t have to rely on the client. The client would get the price in a place the server could get it anyway, so the server should get the price instead.

image

I think you should use MouseButton1Down or MouseButton1Click

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.