RemoteEvent Not Working

You can write your topic however you want, but you need to answer these questions:

  1. I want to decrease a value when a person leaves and their team is red.

  2. What is the issue? Include screenshots / videos if possible!
    The remote event not working.

-- in workspace
local RedAmount = game.ReplicatedStorage.TeamLimits.RedAmount
local BlueAmount = game.ReplicatedStorage.TeamLimits.BlueAmount




game.ReplicatedStorage.DeR.OnServerEvent:Connect(function()
	wait()
	RedAmount.Value = RedAmount.Value - 1
	print("TeamRedAmount Decreased")
end)



-- this is in the startergui
game.Players.PlayerRemoving:connect(function(player)
	if player.Name == game.Players.LocalPlayer.Name then
		if game.Players.LocalPlayer.Team == game.Teams.Red then
		wait(1)
			game.ReplicatedStorage.DeR:FireServer()
		end
	
	end
end)

I have tried renaming and doing things like that and moving the events.

Does it have any errors?

Is “DeR” the RemoteEvent?

What is ReplicatedStorage.TeamLimits? A folder?

DeR is the remote event and teamlimits is a folder with int values also no errors

If TeamLimits is a folder, i think i have the solution:

Folders aren’t accessed this way:
game.ReplicatedStorage.TeamLimits.RedAmount

Try this:
game.ReplicatedStorage["TeamLimits"].RedAmount

Where is the RemoteEvent being fired from? Can you send that script?

I’ve accessed folders with the regular .TeamLimits plenty of times, so I don’t believe it should change much, if anything.

Firstly I advise you to move your workspace script to ServerScriptService.

Secondly, this line is completely useless and should be removed. You might also want to remove your wait() in the script that controls what happens when your RemoteEvent is fired.

It still isn’t clear to me what the error could be. May I please see what the output tells you?

okay
Ima send pictures hold on a sec

I will try that. and the output shows nothing

it did not work. sadly character

image
@Dauhxe
image

Where does the RemoteEvent get fired?

from starter gui the script TeamDecreaser

Could you send that script’s code?

look at the post where I put

– in startergui

I put print all over the script that fires the event and they all printed

Alright I am not sure why you are using a LocalScript in the StarterGui for this but it is much better to do everything in a single Server Script in ServerScriptService like so:

local RedAmount = game:GetService("ReplicatedStorage").TeamLimits.RedAmount
local BlueAmount = game:GetService("ReplicatedStorage").TeamLimits.BlueAmount

game:GetService("Players").PlayerRemoving:Connect(function(player)
	if player.Team == game:GetService("Teams").Red then
		RedAmount.Value = RedAmount.Value - 1
	end
end)
1 Like

I will try this and you are right why am I putting it in the startergui.

In addition, this will also make exploiters unable to fire the RemoteEvent that removes points from a team, because it won’t exist.

In the StarerGui code which is triggered from the .PlayerRemoving event:

	if game.Players.LocalPlayer.Team == game.Teams.Red then
	wait(1)
		game.ReplicatedStorage.DeR:FireServer()
	end

When the player leaves the game, their window is closed and Roblox stops executing scripts, so effectively you are waiting for 1 second but then the game leaves so the code will never reach the :FireServer() line.

It is best practice to handle this sort of script on the server! Set up a script on the server somewhere that detects players leaving instead of the client doing it.

1 Like