-- Script in ServerScriptService
local rs = game:GetService("ReplicatedStorage")
local findcrate = rs:WaitForChild("Events").SourceCrate
local sellcrate = rs:WaitForChild("Events").SellCrates
local pgui = game.Players:WaitForChild(p.Name):WaitForChild ("PlayerGui")
local mgui = pgui:WaitForChild ("MainUI"):WaitForChild ("MobileGui")
local button = mgui:WaitForChild ("Crates"):WaitForChild ("SellButton")
local button2 = mgui:WaitForChild ("Crates"):WaitForChild ("SourceButton")


findcrate.OnServerEvent:connect(function(plr, uniquekey, val)
	if uniquekey ~= script.SourceCrate.Value then return end
	
	if plr.Money.Value >= 5000 then
	plr.Money.Value = plr.Money.Value - 5000	
	plr.Crates.Value = plr.Crates.Value + 3
		if plr.Crates.Value == 14 then
		plr.Crates.Value = plr.Crates.Value + math.random(1,2)
		if plr.Crates.Value == 15 then
			plr.Crates.Value = plr.Crates.Value + math.random(1)
		if plr.Crates.Value == 16 then
			button.Visible = false
		elseif plr.Money.Value<=4999 then
			
				end
			end
		end	
	end
end)

-- local script in a GUI
local plr = game:GetService("Players").LocalPlayer
local maxamount = game.WorkspaceWarehouseSML.Crates
local money = game.Players.LocalPlayer.Money
local rs = game:GetService("ReplicatedStorage")
local source = rs:WaitForChild("Events").SourceCrate

script.Parent.MouseButton1Down:Connect(function()
	source:FireServer("S0URC3")
end)

I'm trying to accomplish a player clicking a button it will add to a crate value and subtract 5,000 money. What did I do incorrectly?

3 comments

0

Put prints throughout it and see where it goes wrong

0

if you're attempting to increase money on the client but subtract on the server, it wont work.

0

How could I make it work correctly What did I do wrong?