I really don't know why this doesn't work. The script doesn't wait for the player, instead it calls it a nil value. What do i do?
plr = game.Players:WaitForChild("LocalPlayer") char = plr:WaitForChild("Character") hum = char:WaitForChild("Humanoid") hum.Died:Connect(function() wait(5) game:GetService("ReplicatedStorage").LC:FireServer() end)
children
of objects. The value of LocalPlayer
is in fact a child of the Players
service, but the property itself is not. Your script is literally waiting for a user named "LocalPlayer" to join the game.local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() -- if character returns nil, we will wait instead local hum = char:WaitForChild("Humanoid") hum.Died:Connect(function() wait(5) game:GetService("ReplicatedStorage").LC:FireServer() end)
Script
to access LocalPlayer
. Sadly, this will not work.DataModel
and the Players
service) of a LocalScript
is, well, the Player
object/LocalPlayer
unless it was placed in ReplicatedFirst
. Objects in ReplicatedFirst
are the first thing to be replicated to the client, and not the server. And LocalScript
s run on behalf of the client. Script
s run on behalf of the server.LocalScript
is your LocalScript
, it works for you. But your classroom is your classroom, and in it are your classmates as well as your teacher. Think of the classroom as the server. It has everyone in it, and cannot keep track of who in the heck LocalPlayer
is! For this reason, LocalPlayer
is nil on the server. The server isn't meant to do work for one specific player, but for all. Your game could have multiple players in it, and when you try accessing LocalPlayer
, it can't just randomly pick a player. Code cannot read your mind. This is why it must be all typed out. So instead of doing this:make a part inside of the workspace with color red
local part = Instance.new("Part") part.BrickColor = BrickColor.new("Really red") part.Parent = workspace