How do i fire a remoteevent each time the player spawns

One second and i’ll send one here.

1 Like

did you try my script?
it would work fine.
make sure to define the player as an arg.

1 Like

i used this and no event was fired

local char = script.Parent
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
RemoteEvent:FireClient()

you have to define the player as an arg.

1 Like

its RemoteEvent:FireServer() for LocalScripts

1 Like

It is inside of a server script

local char = script.Parent
local Player = game.Players:GetPlayerFromCharacter(char)
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
RemoteEvent:FireClient(Player)
1 Like
  • Script Contents:

// METHOD 1 - You can make your code look fancier while also adding more functionality:


Script, ServerScriptService, RespawnScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local remoteEvent = replicatedStorage.ClientServerCommunication

players.PlayerAdded:Connect(function(playerInstance)
	playerInstance.CharacterAdded:Connect(function(playerCharacter)
		remoteEvent:FireClient(playerInstance, replicatedStorage.AddTrail, playerCharacter)
	end)
end)

LocalScript, StarterPlayerScripts, ClientServerCommunication
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.ClientServerCommunication

remoteEvent.OnClientEvent:Connect(function(event, args1, args2)
	event:FireServer(args1, args2)
end)

Script, ServerScriptService, TrailScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.AddTrail

remoteEvent.OnServerEvent:Connect(function()
	-- Code to run in order to add trail.
end)

  • Alternative:

// METHOD 2 - You can just put the trail script inside the RespawnScript.


Script, ServerScriptService, RespawnScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local remoteEvent = replicatedStorage.ClientServerCommunication

players.PlayerAdded:Connect(function(playerInstance)
	playerInstance.CharacterAdded:Connect(function(playerCharacter)
		local att1 = Instance.new("Attachment", playerCharacter.UpperTorso)
		local att2 = Instance.new("Attachment", playerCharacter.LowerTorso)
		local whitetrail = script.WhiteTrail
		local trail = whitetrail:Clone()
		trail.Parent = playerCharacter
		trail.Attachement0 = att1
		trail.Attachement1 = att2
	end)
end)
1 Like

You shouldn’t need to fire a RemoteEvent, both the client and the server are capable of detecting when a character is loaded in.

2 Likes

@ayoub50 @Danielhoteaale ill test the scripts when I’m on my pc again, I had to get off because of the heat, it was running at like 5 fps in studio and Roblox itself too.

It would be easier to just add the trail when the user joins:

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

players.PlayerAdded:Connect(function(playerInstance)
	playerInstance.CharacterAdded:Connect(function(playerCharacter)
		local att1 = Instance.new("Attachment", playerCharacter.UpperTorso)
		local att2 = Instance.new("Attachment", playerCharacter.LowerTorso)
		local whitetrail = script.WhiteTrail
		local trail = whitetrail:Clone()
		trail.Parent = playerCharacter
		trail.Attachment0 = att1
		trail.Attachment1 = att2
	end)
end)

You should end up with something like this every time the user respawns:
image

Could be different beacuse of the trail.

2 Likes

It would’ve been easier yea, but I use more than 20 trails and particles (not included atm they’re broken) so it’s hard to rewrite it all in a different format.

i made all the scripts like u said, just so you know, i didnt change anything about the trailscript in serverscriptservice except for the name, the script thats inside looks like this and i thought it was good:

local remoteevent = game.ReplicatedStorage.RemoteEvent
local trail = game.ServerStorage.Trail
local Particle = game.ServerStorage:WaitForChild("ParticleEmitter")

remoteevent.OnServerEvent:Connect(function(player)
	local character = player.Character

	-- Trail 1
	local trail1 = trail:Clone()
	trail1.Parent = character
	local attachment0 = Instance.new("Attachment", character.Head)
	attachment0.Name = "TrailAttachment0"
	local attachment1 = Instance.new("Attachment", character.UpperTorso)
	attachment1.Name = "TrailAttachment1"

	trail1.Attachment0 = attachment0
	trail1.Attachment1 = attachment1

	-- Trail 2
	local trail2 = trail:Clone()
	trail2.Parent = character
	local attachment2 = Instance.new("Attachment", character.RightUpperArm)
	attachment2.Name = "TrailAttachment2"
	local attachment3 = Instance.new("Attachment", character.RightLowerArm)
	attachment3.Name = "TrailAttachment3"

	trail2.Attachment0 = attachment2
	trail2.Attachment1 = attachment3

	-- Trail 3
	local trail3 = trail:Clone()
	trail3.Parent = character
	local attachment4 = Instance.new("Attachment", character.RightLowerArm)
	attachment2.Name = "TrailAttachment4"
	local attachment5 = Instance.new("Attachment", character.RightHand)
	attachment3.Name = "TrailAttachment5"

	trail3.Attachment0 = attachment4
	trail3.Attachment1 = attachment5

	-- Trail 4
	local trail4 = trail:Clone()
	trail4.Parent = character
	local attachment6 = Instance.new("Attachment", character.LeftUpperArm)
	attachment6.Name = "TrailAttachment4"
	local attachment7 = Instance.new("Attachment", character.LeftLowerArm)
	attachment7.Name = "TrailAttachment5"

	trail4.Attachment0 = attachment6
	trail4.Attachment1 = attachment7

	-- Trail 5
	local trail5 = trail:Clone()
	trail5.Parent = character
	local attachment8 = Instance.new("Attachment", character.LeftLowerArm)
	attachment6.Name = "TrailAttachment4"
	local attachment9 = Instance.new("Attachment", character.LeftHand)
	attachment7.Name = "TrailAttachment5"

	trail5.Attachment0 = attachment8
	trail5.Attachment1 = attachment9
	
	-- Trail 6
	local trail6 = trail:Clone()
	trail6.Parent = character
	local attachment10 = Instance.new("Attachment", character.LowerTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment11 = Instance.new("Attachment", character.UpperTorso)
	attachment7.Name = "TrailAttachment5"

	trail6.Attachment0 = attachment10
	trail6.Attachment1 = attachment11
	
	-- Trail 7
	local trail7 = trail:Clone()
	trail7.Parent = character
	local attachment12 = Instance.new("Attachment", character.UpperTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment13 = Instance.new("Attachment", character.RightUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail7.Attachment0 = attachment12
	trail7.Attachment1 = attachment13
	
	-- Trail 8
	local trail8 = trail:Clone()
	trail8.Parent = character
	local attachment14 = Instance.new("Attachment", character.UpperTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment15 = Instance.new("Attachment", character.LeftUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail8.Attachment0 = attachment14
	trail8.Attachment1 = attachment15
	
	-- Trail 9
	local trail9 = trail:Clone()
	trail9.Parent = character
	local attachment16 = Instance.new("Attachment", character.LeftUpperLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment17 = Instance.new("Attachment", character.LeftLowerLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail9.Attachment0 = attachment16
	trail9.Attachment1 = attachment17
	
	-- Trail 10
	local trail10 = trail:Clone()
	trail10.Parent = character
	local attachment18 = Instance.new("Attachment", character.LeftLowerLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment19 = Instance.new("Attachment", character.LeftFoot
	)
	attachment7.Name = "TrailAttachment5"

	trail10.Attachment0 = attachment18
	trail10.Attachment1 = attachment19
	
	-- Trail 11
	local trail11 = trail:Clone()
	trail11.Parent = character
	local attachment20 = Instance.new("Attachment", character.RightUpperLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment21 = Instance.new("Attachment", character.RightLowerLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail11.Attachment0 = attachment20
	trail11.Attachment1 = attachment21
	
	-- Trail 12
	local trail12 = trail:Clone()
	trail12.Parent = character
	local attachment22 = Instance.new("Attachment", character.RightLowerLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment23 = Instance.new("Attachment", character.RightFoot
	)
	attachment7.Name = "TrailAttachment5"

	trail12.Attachment0 = attachment22
	trail12.Attachment1 = attachment23
	
	-- Trail 13
	local trail13 = trail:Clone()
	trail13.Parent = character
	local attachment24 = Instance.new("Attachment", character.LeftHand)
	attachment6.Name = "TrailAttachment4"
	local attachment25 = Instance.new("Attachment", character.LeftUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail13.Attachment0 = attachment24
	trail13.Attachment1 = attachment25
	
	-- Trail 14
	local trail14 = trail:Clone()
	trail14.Parent = character
	local attachment26 = Instance.new("Attachment", character.RightHand)
	attachment6.Name = "TrailAttachment4"
	local attachment27 = Instance.new("Attachment", character.RightUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail14.Attachment0 = attachment26
	trail14.Attachment1 = attachment27
	
	-- Trail 15
	local trail15 = trail:Clone()
	trail15.Parent = character
	local attachment28 = Instance.new("Attachment", character.RightFoot)
	attachment6.Name = "TrailAttachment4"
	local attachment29 = Instance.new("Attachment", character.RightUpperLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail15.Attachment0 = attachment28
	trail15.Attachment1 = attachment29
	
	-- Trail 16
	local trail16 = trail:Clone()
	trail16.Parent = character
	local attachment30 = Instance.new("Attachment", character.LeftFoot)
	attachment6.Name = "TrailAttachment4"
	local attachment31 = Instance.new("Attachment", character.LeftUpperLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail16.Attachment0 = attachment30
	trail16.Attachment1 = attachment31
	
	-- Trail 17
	local trail17 = trail:Clone()
	trail17.Parent = character
	local attachment32 = Instance.new("Attachment", character.UpperTorso
	)
	attachment6.Name = "TrailAttachment4"
	local attachment33 = Instance.new("Attachment", character.RootPart
	)
	attachment7.Name = "TrailAttachment5"

	trail17.Attachment0 = attachment32
	trail17.Attachment1 = attachment33
	
	local particle2 = particle:Clone()
	particle2.Enabled = true
	particle2.Parent = character.UpperTorso
	
	local particle3 = particle:Clone()
	particle3.Enabled = true
	particle3.Parent = character.LowerTorso
	
	local particle4 = particle:Clone()
	particle4.Enabled = true
	particle4.Parent = character.LeftFoot
	
	local particle5 = particle:Clone()
	particle5.Enabled = true
	particle5.Parent = character.LeftLowerLeg
	
	local particle6 = particle:Clone()
	particle6.Enabled = true
	particle6.Parent = character.LeftUpperLeg
	
	
	local particle7 = particle:Clone()
	particle7.Enabled = true
	particle7.Parent = character.RightFoot
	
	local particle8 = particle:Clone()
	particle8.Enabled = true
	particle8.Parent = character.RightLowerLeg
	
	local particle9 = particle:Clone()
	particle9.Enabled = true
	particle9.Parent = character.RightUpperLeg
	
	local particle10 = particle:Clone()
	particle10.Enabled = true
	particle10.Parent = character.LeftHand
	
	local particle11 = particle:Clone()
	particle11.Enabled = true
	particle11.Parent = character.LeftLowerArm
	
	local particle12 = particle:Clone()
	particle12.Enabled = true
	particle12.Parent = character.LeftUpperArm
	
	local particle13 = particle:Clone()
	particle13.Enabled = true
	particle13.Parent = character.RightHand
	
	local particle14 = particle:Clone()
	particle14.Enabled = true
	particle14.Parent = character.RightLowerArm
	
	local particle15 = particle:Clone()
	particle15.Enabled = true
	particle15.Parent = character.RightUpperArm

end)

also there was no remote event launch again…

Try checking for when the player joins using the player joined event, and send the remote event out. and when their health is = 0 or less, then send out the remote event (assuming your death time is a few seconds.) I recommend scripting it yourself, as it’s good practice, especially in these types of scripts.

I really don’t know why, I tested it in a game and it worked perfectly.

1 Like

I’ll send the original script and the remoteevent script when I get home, maybe there’s something I’m missing that should’ve been put there

this is the original script that activates the remoteevent, this one is the one which activates as soon as the player hits shift (and not 50) and also never dissapears, a wrong script. But this activated the remoteevent just fine so:

local player = game.Players.LocalPlayer
local character = player.Character or script.Parent
local humanoid = character.Humanoid
local remoteevent = game.ReplicatedStorage.RemoteEvent


while humanoid.WalkSpeed == 16 do
	print(humanoid.WalkSpeed)

	for i,v in pairs(character:GetChildren()) do
		if v:IsA("Trail") then
			v:Destroy()
		end
	end

	wait()
end


remoteevent:FireServer()

and this is the script that is the remoteevent, normally also activating particles but that broke for some reason but here it is:

local remoteevent = game.ReplicatedStorage.RemoteEvent
local trail = game.ServerStorage.Trail
local Particle = game.ServerStorage:WaitForChild("ParticleEmitter")

remoteevent.OnServerEvent:Connect(function(player)
	local character = player.Character

	-- Trail 1
	local trail1 = trail:Clone()
	trail1.Parent = character
	local attachment0 = Instance.new("Attachment", character.Head)
	attachment0.Name = "TrailAttachment0"
	local attachment1 = Instance.new("Attachment", character.UpperTorso)
	attachment1.Name = "TrailAttachment1"

	trail1.Attachment0 = attachment0
	trail1.Attachment1 = attachment1

	-- Trail 2
	local trail2 = trail:Clone()
	trail2.Parent = character
	local attachment2 = Instance.new("Attachment", character.RightUpperArm)
	attachment2.Name = "TrailAttachment2"
	local attachment3 = Instance.new("Attachment", character.RightLowerArm)
	attachment3.Name = "TrailAttachment3"

	trail2.Attachment0 = attachment2
	trail2.Attachment1 = attachment3

	-- Trail 3
	local trail3 = trail:Clone()
	trail3.Parent = character
	local attachment4 = Instance.new("Attachment", character.RightLowerArm)
	attachment2.Name = "TrailAttachment4"
	local attachment5 = Instance.new("Attachment", character.RightHand)
	attachment3.Name = "TrailAttachment5"

	trail3.Attachment0 = attachment4
	trail3.Attachment1 = attachment5

	-- Trail 4
	local trail4 = trail:Clone()
	trail4.Parent = character
	local attachment6 = Instance.new("Attachment", character.LeftUpperArm)
	attachment6.Name = "TrailAttachment4"
	local attachment7 = Instance.new("Attachment", character.LeftLowerArm)
	attachment7.Name = "TrailAttachment5"

	trail4.Attachment0 = attachment6
	trail4.Attachment1 = attachment7

	-- Trail 5
	local trail5 = trail:Clone()
	trail5.Parent = character
	local attachment8 = Instance.new("Attachment", character.LeftLowerArm)
	attachment6.Name = "TrailAttachment4"
	local attachment9 = Instance.new("Attachment", character.LeftHand)
	attachment7.Name = "TrailAttachment5"

	trail5.Attachment0 = attachment8
	trail5.Attachment1 = attachment9
	
	-- Trail 6
	local trail6 = trail:Clone()
	trail6.Parent = character
	local attachment10 = Instance.new("Attachment", character.LowerTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment11 = Instance.new("Attachment", character.UpperTorso)
	attachment7.Name = "TrailAttachment5"

	trail6.Attachment0 = attachment10
	trail6.Attachment1 = attachment11
	
	-- Trail 7
	local trail7 = trail:Clone()
	trail7.Parent = character
	local attachment12 = Instance.new("Attachment", character.UpperTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment13 = Instance.new("Attachment", character.RightUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail7.Attachment0 = attachment12
	trail7.Attachment1 = attachment13
	
	-- Trail 8
	local trail8 = trail:Clone()
	trail8.Parent = character
	local attachment14 = Instance.new("Attachment", character.UpperTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment15 = Instance.new("Attachment", character.LeftUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail8.Attachment0 = attachment14
	trail8.Attachment1 = attachment15
	
	-- Trail 9
	local trail9 = trail:Clone()
	trail9.Parent = character
	local attachment16 = Instance.new("Attachment", character.LeftUpperLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment17 = Instance.new("Attachment", character.LeftLowerLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail9.Attachment0 = attachment16
	trail9.Attachment1 = attachment17
	
	-- Trail 10
	local trail10 = trail:Clone()
	trail10.Parent = character
	local attachment18 = Instance.new("Attachment", character.LeftLowerLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment19 = Instance.new("Attachment", character.LeftFoot
	)
	attachment7.Name = "TrailAttachment5"

	trail10.Attachment0 = attachment18
	trail10.Attachment1 = attachment19
	
	-- Trail 11
	local trail11 = trail:Clone()
	trail11.Parent = character
	local attachment20 = Instance.new("Attachment", character.RightUpperLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment21 = Instance.new("Attachment", character.RightLowerLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail11.Attachment0 = attachment20
	trail11.Attachment1 = attachment21
	
	-- Trail 12
	local trail12 = trail:Clone()
	trail12.Parent = character
	local attachment22 = Instance.new("Attachment", character.RightLowerLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment23 = Instance.new("Attachment", character.RightFoot
	)
	attachment7.Name = "TrailAttachment5"

	trail12.Attachment0 = attachment22
	trail12.Attachment1 = attachment23
	
	-- Trail 13
	local trail13 = trail:Clone()
	trail13.Parent = character
	local attachment24 = Instance.new("Attachment", character.LeftHand)
	attachment6.Name = "TrailAttachment4"
	local attachment25 = Instance.new("Attachment", character.LeftUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail13.Attachment0 = attachment24
	trail13.Attachment1 = attachment25
	
	-- Trail 14
	local trail14 = trail:Clone()
	trail14.Parent = character
	local attachment26 = Instance.new("Attachment", character.RightHand)
	attachment6.Name = "TrailAttachment4"
	local attachment27 = Instance.new("Attachment", character.RightUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail14.Attachment0 = attachment26
	trail14.Attachment1 = attachment27
	
	-- Trail 15
	local trail15 = trail:Clone()
	trail15.Parent = character
	local attachment28 = Instance.new("Attachment", character.RightFoot)
	attachment6.Name = "TrailAttachment4"
	local attachment29 = Instance.new("Attachment", character.RightUpperLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail15.Attachment0 = attachment28
	trail15.Attachment1 = attachment29
	
	-- Trail 16
	local trail16 = trail:Clone()
	trail16.Parent = character
	local attachment30 = Instance.new("Attachment", character.LeftFoot)
	attachment6.Name = "TrailAttachment4"
	local attachment31 = Instance.new("Attachment", character.LeftUpperLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail16.Attachment0 = attachment30
	trail16.Attachment1 = attachment31
	
	-- Trail 17
	local trail17 = trail:Clone()
	trail17.Parent = character
	local attachment32 = Instance.new("Attachment", character.UpperTorso
	)
	attachment6.Name = "TrailAttachment4"
	local attachment33 = Instance.new("Attachment", character.RootPart
	)
	attachment7.Name = "TrailAttachment5"

	trail17.Attachment0 = attachment32
	trail17.Attachment1 = attachment33
	
	local particle2 = particle:Clone()
	particle2.Enabled = true
	particle2.Parent = character.UpperTorso
	
	local particle3 = particle:Clone()
	particle3.Enabled = true
	particle3.Parent = character.LowerTorso
	
	local particle4 = particle:Clone()
	particle4.Enabled = true
	particle4.Parent = character.LeftFoot
	
	local particle5 = particle:Clone()
	particle5.Enabled = true
	particle5.Parent = character.LeftLowerLeg
	
	local particle6 = particle:Clone()
	particle6.Enabled = true
	particle6.Parent = character.LeftUpperLeg
	
	
	local particle7 = particle:Clone()
	particle7.Enabled = true
	particle7.Parent = character.RightFoot
	
	local particle8 = particle:Clone()
	particle8.Enabled = true
	particle8.Parent = character.RightLowerLeg
	
	local particle9 = particle:Clone()
	particle9.Enabled = true
	particle9.Parent = character.RightUpperLeg
	
	local particle10 = particle:Clone()
	particle10.Enabled = true
	particle10.Parent = character.LeftHand
	
	local particle11 = particle:Clone()
	particle11.Enabled = true
	particle11.Parent = character.LeftLowerArm
	
	local particle12 = particle:Clone()
	particle12.Enabled = true
	particle12.Parent = character.LeftUpperArm
	
	local particle13 = particle:Clone()
	particle13.Enabled = true
	particle13.Parent = character.RightHand
	
	local particle14 = particle:Clone()
	particle14.Enabled = true
	particle14.Parent = character.RightLowerArm
	
	local particle15 = particle:Clone()
	particle15.Enabled = true
	particle15.Parent = character.RightUpperArm

end)

I can’t seem to understand what’s happening, maybe try the scripts I sent you the first time and see if it works with just one trail.

The reply with this text should make it work.

1 Like

use the characteradded function