This is not the full script, but this is the part of it that's bothering me. Neither of these 2 things get printed and the event doesn't get fired, any ideas on how to fix that?
wait() local players = game:GetService("Players") players.PlayerAdded:Connect(function(plr) local player = players.LocalPlayer local character = player.Character local humanoid = character.Humanoid local hp = character.Humanoid.Health local maxhp = character.Humanoid.MaxHealth print("playeradded") if plr == player then print("plradded") workspace.Events.DFEvents.PhoenixFruitEvents.ParticlesE:FireServer()
You have forgotten to add the ends:=) LocalScript cannot run if its in workspace
From the roblox wiki:
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
A Player’s Backpack, such as a child of a Tool
A Player’s Player/Character|character model
A Player’s PlayerGui
A Player’s PlayerScripts
The ReplicatedFirst service
wait() local players = game:GetService("Players") players.PlayerAdded:Connect(function(plr) local player = players.LocalPlayer local character = player.Character local humanoid = character.Humanoid local hp = character.Humanoid.Health local maxhp = character.Humanoid.MaxHealth print("playeradded") if plr == player then print("plradded") workspace.Events.DFEvents.PhoenixFruitEvents.ParticlesE:FireServer() end end)
here are a few flaws that are are probably leading to errors..
1). You forgot the end
keyword, this will lead to a syntax error
2). The code has to be in a server script
..
3).you can't use Players.LocalPlayer
in a server script..
so here is a example structure that is guaranteed to work:
make sure the code is in server script
local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(player) print(player.Name," has joined the server!") --the rest of the code goes here..! end)
There are a few things that hinder your PlayerAdded
for firing the way you want to.
The first reason is the wait()
at the top of your script. This will yield your script and cause the listener to be connected at a later time, which will not fire for when the first player joins.
The second reason is this being a LocalScript
. LocalScript
connections to a PlayerAdded
event will only fire for the players joining after the client.
An additional note, you should also use the event player.CharacterAdded
to wait for the character to finish loading.