Hello, I have this Sun damage script, that deals damage to the player when touches the Sun and is safe on shadows.
I’m trying to add a BoolValue that when is Enabled you don’t get damage in the Sun.
Where BoolValue is located.
My code
-- Sun script is located in the same folder as Immunity.
local char = game.Players.LocalPlayer.Character
local Immunity = char.PlayerStats:WaitForChild("SunImmunity") -- boolvalue, when enabled The player doesn't get sun damage.
-- PlayerStats is the folder inside StarterCharacterScripts where the strings and the boolvalue is located.
local sunDirection = game.Lighting:GetSunDirection()
local sun_Detect = 1000
local coolDown = 0
local coolDownDuration = 3
local safe = true
local burning = false
function BurnPlayer()
char.Humanoid:TakeDamage(10)
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(char.HumanoidRootPart.Position, sunDirection * sun_Detect)
local partFound = workspace:FindPartOnRay(ray, char)
if partFound then
safe = true
Safe()
else
safe = false
coolDown = math.max(0, coolDown - deltaTime)
if coolDown <= 0 then
if burning == false then
burning = false
BurnPlayer()
else
coroutine.yield()
end
end
end
end)
game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
sunDirection = game.Lighting:GetSunDirection()
end)
A server-script cannot access game.Players.LocalPlayer. Consider making sure workspace.RejectCharacterDeletions is true and put this server-script in StarterCharacterScripts.
-- Sun script is located in the same folder as Immunity.
local char = script.Parent
local Immunity = char.PlayerStats:WaitForChild("SunImmunity") -- boolvalue, when enabled The player doesn't get sun damage.
-- PlayerStats is the folder inside StarterCharacterScripts where the strings and the boolvalue is located.
local sunDirection = game.Lighting:GetSunDirection()
local sun_Detect = 1000
local coolDown = 0
local coolDownDuration = 3
local safe = true
local burning = false
function BurnPlayer()
char.Humanoid:TakeDamage(10)
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(char.HumanoidRootPart.Position, sunDirection * sun_Detect)
local partFound = workspace:FindPartOnRay(ray, char)
if partFound then
safe = true
Safe()
else
safe = false
coolDown = math.max(0, coolDown - deltaTime)
if coolDown <= 0 then
if burning == false then
burning = false
BurnPlayer()
else
coroutine.yield()
end
end
end
end)
game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
sunDirection = game.Lighting:GetSunDirection()
end)
Hello, yeah I tried it and works exactly like before, the reason I added game.Players.LocalPlayer, is because I have a script disabled in other system for this one, like a race, if they are in a determined race the script disables or enables and works perfectly.
What I’m trying to do is add the boolvalue “SunImmunity”, is a value of a clan perk, because if you are in a race that can burn in the sun I’m trying to add this value, that if you are in the determined clan, you get the sunimmunity.
They could just set the script’s RunContext to client; but even then, if it is a LocalScript, it should work as a descendant of the character. Either way, it should run.
That’s because you are trying to cast with the ray instance. To convert it, you would just cast from the ray’s origin and direction.
--optional RaycastParams
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Exclude
local partFound = workspace:Raycast(ray.Origin, ray.Direction * 15, params)
Or, just cast using the origin and direction given to Ray.new. Make sure to multiply the direction to reach the length you want the ray to be.
Since workspace:FindPartOnRay is deprecated, it is no longer updated and will eventually become non-functional. Converting it now might save you a headache later on.