Sun Script not working

hello
I need help with a sun Script
it kills the player if he get’s any sunlight every (any)

here is the error if that help’s

RunService:fireRenderStepEarlyFunctions unexpected error while invoking callback: Poition is not a valid member of Part “Workspace.zeinbanana882.HumanoidRootPart”

did I see Any help no

ty if you helped me


local sunDirection = game.Lighting:GetSunDirection()


local sun_Detect = 10000
local coolDown = 0
local coolDownDuration = 1

local Safe = true
local Burning = false

function BurnPlayer()
    character.Humanoid.TakeDamage(5)
    Burning = false
    coolDown = coolDownDuration
end

function Safe()
    if Burning == true then
        Burning = false
    end
end

game:GetService("RunService"):BindToRenderStep("SunService", Enum.RenderPriority.Camera.Value + 1, function(deltaTime)
    local ray = Ray.new(character.HumanoidRootPart.Poition, sunDirection,sun_Detect)
    local PartFound = workspace:FindPartOnRay(ray, character)

    if PartFound then
        Safe = true
        print("your good")
        Safe()
    else
        Safe = false
        coolDown = math.max(0, coolDown, deltaTime)
        if coolDown <= 0 then
            if Burning == false then
                Burning = true
                BurnPlayer()
            else
                coroutine.yield()

            end
        end
        print ("Find Player")
    end
end)

game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
    sunDirection = game.Lighting:GetSunDirection()
end)

The error is being caused due to a typo, Poition instead of Position:

should be:

local ray = Ray.new(character.HumanoidRootPart.Position, sunDirection, sun_Detect)
1 Like

Also in the BurnPlayer function you should change this:

character.Humanoid.TakeDamage(5)

to this: (: instead of .)

character.Humanoid:TakeDamage(5)

A lot of syntax errors.

  1. Poition instead of Position
  2. .TakeDamage instead of :TakeDamage
  3. math.max(0,coolDown,deltaTime) instead of math.max(0,coolDown - deltaTime)
  4. Safe() function conflicted with the Safe variable, so i changed it to SetSafe().
local sunDirection = game.Lighting:GetSunDirection()

local sun_Detect = 10000
local coolDown = 0
local coolDownDuration = 1

local Safe = true
local Burning = false

local function BurnPlayer()
	character.Humanoid:TakeDamage(5)
	Burning = false
	coolDown = coolDownDuration
end

local function SetSafe()
	if Burning then
		Burning = false
	end
end

game:GetService("RunService"):BindToRenderStep("SunService", Enum.RenderPriority.Camera.Value + 1, function(deltaTime)
	local ray = Ray.new(character.HumanoidRootPart.Position, sunDirection * sun_Detect)
	local PartFound = workspace:FindPartOnRay(ray, character)

	if PartFound then
		Safe = true
		print("you're good")
		SetSafe()
	else
		Safe = false
		coolDown = math.max(0, coolDown - deltaTime)
		if coolDown <= 0 then
			if not Burning then
				Burning = true
				BurnPlayer()
			end
		end
		print("Find Player")
	end
end)

game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
	sunDirection = game.Lighting:GetSunDirection()
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.