How do i fire a remoteevent each time the player spawns

how would i go about firing a remoteevent each time the player loads in, on join and when they die and respawn (remoteevent is adding trails into the bodyparts, and they need to be there at all times.)

What do you want to achieve?
do you want to fire a remotevent when a player joins the game or something else?

yes, each player that joins should have a remoteevent fired and each time they reset too because i think the trails get removed when they die

Try this:

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local remoteEvent = replicatedStorage.RemoteEvent

players.PlayerAdded:Connect(function(playerInstance)
	playerInstance.CharacterAdded:Connect(function(playerCharacter)
		-- Run any code whenever the player's character loads in or run the Remote Event
		-- remoteEvent:FireClient(playerInstance)
	end)
end)
3 Likes
-- Server Side Script --

-- When Player Joins, fire a event --
local RemoteEvent = game.ReplicatedStorage.Event -- Put Path to event here
game.Players.PlayerAdded:Connect(function())
    RemoteEvent:FireClient()
end)

-- When player dies, fire a event --
game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function()
        RemoteEvent:FireClient()
    end)
end)

I am not that good at scripting but try the above code

if the “Player Die, fire a event” code dosen’t work, see the above website.

1 Like

i tested it out and added a print to see if it launched, tho i checked the output and no print

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local remoteevent = game.ReplicatedStorage.RemoteEvent

players.PlayerAdded:Connect(function(playerInstance)
	playerInstance.CharacterAdded:Connect(function(playerCharacter)
		print("event fired")
		remoteevent:FireServer()
	end)
end)

Maybe this will work:

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local remoteEvent = replicatedStorage.RemoteEvent

players.PlayerAdded:Connect(function(playerInstance)
	playerInstance.CharacterAdded:Connect(function(playerCharacter)
		print("Hello, World!")
	end)
end)

Also make sure the Script is in ServerScriptService and it’s NOT a LocalScript.

1 Like

you can aswell make a script in StarterCharacterScripts

local char = script.Parent
local Player = game.Players:GetPlayerFromCharacter(char)
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
--
RemoteEvent:FireServer()
--OR/--
RemoteEvent:FireClient(Player)
--
1 Like

I put this script in serverscriptservice but didnt get any output again

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local remoteEvent = replicatedStorage.RemoteEvent

players.PlayerAdded:Connect(function(playerInstance)
	playerInstance.CharacterAdded:Connect(function(playerCharacter)
		print("Hello, World!")
		remoteEvent:FireServer()
	end)
end)

Can you try my code out? wanna know if mine works or not lol

1 Like

Remove the “remoteEvent:FireServer()” line. Only fire it if you have a RemoteEvent by that name in ReplicatedStorage.

1 Like

the remote event in replicated storage is named like that tho
image

used this, no output

-- Server Side Script --

-- When Player Joins, fire a event --
local RemoteEvent = game.ReplicatedStorage.RemoteEvent -- Put Path to event here
game.Players.PlayerAdded:Connect(function()
	print("event")
RemoteEvent:FireClient()
end)

-- When player dies, fire a event --
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		RemoteEvent:FireClient()
	end)
end)

Ohhh wait, your script says remoteEvent:FireServer() but you can’t call FireServer() from a Script.

what do i do instead of that ?

you have to fire the client instead RemoteEvent:FireClient() and make sure to define the player instance in it.

1 Like

this will work for both serverscript/localscript

1 Like

You can make some sort of Client/Server Communication Script to do that.

1 Like

I could send one if you need it.

1 Like

if you could i would appreciate it