Upgrade Failed But There Is No Error

My upgrade system isn’t working Upgrade Failed shows in the output without an error coming up. Also how would I try to debug this?

Lcoal Script

local replicatedStorage = game:GetService("ReplicatedStorage")--Defines replicated storage
local upgrades = game.Players.LocalPlayer.PlayerGui.ScreenGui2.Upgrade.Cost.Cost:WaitForChild('UpgradesIntValue')
local RemoteEvent = game.ReplicatedStorage.RemoteEvent

local success--Variable

script.Parent.MouseButton1Click:Connect(function()
	success = false
	if upgrades.Value < 100 then
		success = RemoteEvent:FireServer()
		
	end
	if success then
		print("Upgraded Successfully")
	else
			print("Upgrade Failed")
	end
end)

ServerScript

local Event = game.ReplicatedStorage.RemoteEvent
Event.OnServerEvent:Connect(function(player)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local upgrades = game.Players:FindFirstChild(player.Name).PlayerGui.ScreenGui2.Upgrade.Cost.Cost:WaitForChild('UpgradesIntValue')

local increase = 1.5
local price = upgrades.Value*increase



if player.leaderstats.Elixir.Value >= price then
	player.leaderstats.Elixir.Value = player.leaderstats.Elixir.Value - price
	
	upgrades.Value = upgrades.Value + 1
	return true 
else
		return false
end

end)

Two things, are you sure the remote-event is being fired? are you sure the player has enough price? I would encourage you to add some print statements to debug your code.

Change this:

--Script 1:
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
--Script 2: 
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

To this

--Script 1:
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
--Script 2: 
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent:FireServer()
This does not return a success value so your if statement will always be false. If you want the server to return something back to the client, use a RemoteFunction instead.

1 Like

I don’t see a difference between the two.

1 Like