Script doesn't detect the character from the player

  • Hello devs!
    I have a script for my boss fighting game, but it doesn’t work…
    Here is my code:
local Circle = game.ServerStorage.ExplosionPart
local function onLoop(player)
	if game.Lighting.ColorCorrection.TintColor == Color3.fromRGB(177, 0, 0) then
		local char = player.CharacterAdded:Wait()
		Circle.CFrame = char.Torso.CFrame
	end
end
while wait(5) do
	onLoop()
end

And here is the bug in the output:
Capture d’écran 2021-06-14 214902
Any help is appreciated!

1 Like

Characteradded is a signal, try

local character = player.Character or player.CharacterAdded:Wait()

player.CharacterAdded:Connect(function (newChar)
    character = newChar
end)
local function onLoop(player)
...
player.CharacterAdded:Wait()

It seems we’re calling player from our parem up here

But you can see from the loop, we are not passing the player

Screen Shot 2021-06-14 at 3.06.24 PM

Meaning player is nil

Hi there! There are a few errors in your script.

First of all, I’m 99% the script returns an error because player isn’t defined.

Second thing, CharacterAdded is an event, so instead of using player.CharacterAdded:Wait() you should use player.CharacterAdded:Connect(Your_Function_Here).

1 Like