RemoteEvents not working?

So I’m working on a game and when I try to fire a remote it won’t do what it’s supposed to do.
Server:

OnClick.OnServerEvent:Connect(function(Player)
	local PlayerLeaderstats = Player:WaitForChild("leaderstats")
	local PlayerRawStats = Player:WaitForChild("RawStats")
	
	local Taps = PlayerLeaderstats:WaitForChild("Taps")
	local Rebirths = PlayerLeaderstats:WaitForChild("Rebirths")
	local TotalTaps = PlayerRawStats:WaitForChild("TotalTaps")
	local ClicksPerSecond = PlayerRawStats:WaitForChild("ClicksPerSecond")
	
	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId,12423824) then -- 12423824
		Taps.Value = Taps.Value + ClicksPerSecond.Value * 2 * (Rebirths.Value + 1)
		TotalTaps.Value =  TotalTaps.Value + ClicksPerSecond.Value * 2 * (Rebirths.Value + 1)
	else
		Taps.Value = Taps.Value + ClicksPerSecond.Value * (Rebirths.Value + 1)
		TotalTaps.Value =  TotalTaps.Value + ClicksPerSecond.Value * (Rebirths.Value + 1)
	end
end)

Client

local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
local Event = RemotesFolder:WaitForChild("OnClick")

--<Functions>--
TapButton.MouseButton1Click:Connect(function()
	Event:FireServer()
	TapSound:Play()
	TapShadow.BackgroundColor3 = Color3.fromRGB(255,255,255)
	wait(0.1)
	TapShadow.BackgroundColor3 = Color3.fromRGB(29, 33, 37)
end)

Video

Hmm. because of the background colour changing, it seems to me that the remote event is being sent over from the client. So it’s likely to be an issue on the server. Prints can be a great tool for debugging and it can tell us much more about the problem, e.g, where the issue specifically is at, what parts of the code aren’t running.

I assume you have defined the path to your remotes as well as any other services.

local MarketPlaceService = game:GetService("MarketplaceService")
local gamePassID = 12423824
local event = game.ReplicatedStorage.RemoteEvent 

Event.OnServerEvent:Connect(function(Player)
local PlayerLeaderstats = Player:WaitForChild("leaderstats")
local PlayerRawStats = Player:WaitForChild("RawStats")
local Taps = PlayerLeaderstats:WaitForChild("Taps")
local Rebirths = PlayerLeaderstats:WaitForChild("Rebirths")
local TotalTaps = PlayerRawStats:WaitForChild("TotalTaps")
local ClicksPerSecond = PlayerRawStats:WaitForChild("ClicksPerSecond")

 -- More likely an issue after here -- I would wrap it an pcall just in case.
  local success, hasPass = pcall(function()
	 MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, gamePassID)
end)

  	if not success then -- Error 
    else

       if hasPass then -- Player has gamepass
        Taps.Value = Taps.Value + ClicksPerSecond.Value * 2 * (Rebirths.Value + 1)
	    TotalTaps.Value =  TotalTaps.Value + ClicksPerSecond.Value * 2 * (Rebirths.Value + 1)

       else
       -- Player doesn't have pass
        Taps.Value = Taps.Value + ClicksPerSecond.Value * (Rebirths.Value + 1)
	    TotalTaps.Value =  TotalTaps.Value + ClicksPerSecond.Value * (Rebirths.Value + 1)
        end
	end
end)
1 Like