Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to go around not firing Remotes?

##Main Problem

I am making a round script that uses a Remote Event (Client --> Server). When the player dies, it just doesn't fire again. How can I go around this?

Server

--\\ Services
local repStorage = game:GetService("ReplicatedStorage")
--\\ Network Data
local remoteEvent = repStorage:WaitForChild("RemoteEvent")
--\\ Remote Event Example
remoteEvent:FireAllClients()

Client

--\\ Services
local repStorage = game:GetService("ReplicatedStorage")
--\\ Network Data
local remoteEvent = repStorage:WaitForChild("RemoteEvent")
--\\ Remote Example
remoteEvent.OnClientEvent:Connect(function() -- Player dies, doesn't fire
	while wait() do 
		print("oof") 
	end
end)

##A Solution I Thought Of

Instead of an anonymous event, I could use functions and make a separate line that listens for the event. I will do that again but that line will be wrapped by an anonymous event:

Client

--\\ Services
local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
--\\ Player Components
local player = players.LocalPlayer
--\\ Character Components
local char = player.Character
local hum = char:WaitForChild("Humanoid")

--\\ Network Data
local remoteEvent = repStorage:WaitForChild("RemoteEvent")
--\\ Remote Example
local function onClientEvent()
	while wait() do 
		print("oof") 
	end
end

remoteEvent.OnClientEvent:Connect(onClientEvent)

hum.Died:Connect(function()
	remoteEvent.OnClientEvent:Connect(onClientEvent)
end)

The server is the same

But, that did nothing, the same thing happened.

I cannot think of any other solution.

2 comments

0

Mabe you can make a function to remove script when plr dies? With humanoid health?

0

Why would I want to destroy the script if I want it to continue?

1 answer

Whenever the player dies, it creates a new humanoid. And since you only declare the humanoid once, it will only work the first time the player dies. You could use a function like this...

player.CharacterAdded:connect(function(character)
	character.Humanoid.Died:connect(function()
		print'fire event'
	end)
end)

This will make sure that whenever the character is created again (after death) it will pick up the new humanoid and trigger the death event.

4 comments

0

Wait, I wrap this around my OnClientEvent?

0

I don't think this might work because I need to at least fire the event once. So, I don't see this to be a valid answer

0

Well if you want the client event to trigger when the player dies, you wouldn't even need a remote to access the client so you could use a function? Am I understanding that right, that you want the event to trigger on the player's death? If so then you would fire the event within the humanoid.Died event.

0

Okay, I don't think you understand. The remote event should fire. Even though the player dies, the event should continue or restart again or something.

This discussion is preserved as it was. New answers, comments, and votes are closed.