Okay guys hoping you can help me out here, I need this part
repeat wait() until player.Character ~= nil
in my LocalScript because it later complains about in Server log
-- character not being a valid member of Model
from this line
local character = player.Character
I understand why this is occurring, the script is running before the Character is created, that is why I have that repeat up there. The issue with the repeat is that, after the Character is no longer nil, the script will never re-run. So, if the player resets, the LocalScript is useless because of that statement because it won't run again. What else can I do?
Full Script
local player = script.Parent.Parent repeat wait() until player.Character ~= nil local character = player.Character local humanoid = character.Humanoid local repStorage = game:GetService("ReplicatedStorage") local event = repStorage:WaitForChild("RemoteEvent") game.Players.LocalPlayer.Character.Humanoid.Health==0 do wait(); end humanoid.Died:connect(function(Died) print('Checking if the boss dies') for i, v in pairs(game.Players:GetChildren()) do if v.TeamColor == BrickColor.new('Bright red') and player.Name == v.Name then event:FireServer() end end end)
Here this should work like a charm. Don't use a repeat loop for this kind of stuff.
local Plr = game:GetService("Players").LocalPlayer local Char = Plr.Character or Plr.CharacterAdded:wait() -- Bla Bla Bla Bla
Please learn how to organise your code. And also explain your problem better.