I’m trying to make it so that when a player leaves the game while they’re in chapter 1 the chapter 1 playing count will go down. I’m doing this with a remote event in replicated storage, a local script in starter player scripts and a script in server script service. There is also a value inside of the player’s backpack holding whether or not they’re playing chapter 1 and a value in a workspace folder that holds the number of players in chapter 1.
The local script that fires the event prints fired but the remote event doesn’t do anything even though it says it fired.
Here is the local script that fires the remote event:
game.Players.PlayerRemoving:Connect(function(plr)
if plr.Backpack.C1Playing.Value == ("Yes") then
game.ReplicatedStorage:WaitForChild("C1PlayerRemoveEvent"):FireServer()
print("Remove Event Fired") -- THIS PRINS SO THE EVENT IS BEING FIRED
end
end)
Here is the script that powers the remote event:
game.ReplicatedStorage:WaitForChild("C1PlayerRemoveEvent").OnServerEvent:Connect(function()
print("The Event Started To Work") -- Doesn't Print
workspace.ValueStorer.C1Players.Value = workspace.ValueStorer.C1Players.Value - 1
task.wait(1)
print("They Stopped")
print("Stopped Playing C1")
end)
Why not just do this with a IntValue alone? It’d be way more easier on your approach rather than just using a RemoteEvent, as workspace Objects will replicate within the client as long as they’re being handled on the server
-- Server Script inside ServerScriptService
local CurrentPlayers = workspace:WaitForChild("IntValue")
local function PlayerRemoving(Plr)
local Backpack = Plr:WaitForChild("Backpack")
local C1 = Backpack:WaitForChild("C1Playing")
if C1.Value == "Yes" then
CurrentPlayers.Value -= 1
print("This works")
end
end
game.Players.PlayerRemoving:Connect(PlayerRemoving)
-- Thine LOCALSCRIPT
local CurrentPlayers = workspace:WaitForChild("IntValue")
local function ChangeValue(NewVal)
print("Someone left, players remaining:", NewVal)
end)
CurrentPlayers.Changed:Connect(ChangeValue)
Just simply handle a Changed event on the LocalScript (Also I just realized how your scripts are being handled and you should’ve probably switched them up)
I would handle how you decide what players are in what chapters are in a different way. Using a RemoteEvent under a local .PlayerRemoving event is not a good design choice.