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)
-- 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.
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.
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)
--
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
Remove the “remoteEvent:FireServer()” line. Only fire it if you have a RemoteEvent by that name in ReplicatedStorage.
the remote event in replicated storage is named like that tho
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.
this will work for both serverscript/localscript
You can make some sort of Client/Server Communication Script to do that.
I could send one if you need it.
if you could i would appreciate it