I have this Sun damage script, that is actually a Server side script, it works in Server but not in local (Sometimes).
This is where the script is located.
This is what I mean.
I tested it in a Local Server in studio and it works perfectly, if I play in studio the video above happens and if I play in game nothing happens, I don’t get damage.
My code
local char = script.Parent
local Immunity = char.PlayerStats:WaitForChild("SunImmunity") -- boolvalue, when enabled The player doesn't get sun damage.
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
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Exclude
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:Raycast(ray.Origin, ray.Direction * 15, params)
if partFound then
safe = true
Safe()
else
safe = false
coolDown = math.max(0, coolDown - deltaTime)
if coolDown <= 0 then
if not burning and char.PlayerStats.SunImmunity.Value == false then
burning = false
BurnPlayer()
end
end
end
end)
game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
sunDirection = game.Lighting:GetSunDirection()
end)
In studio you are both client and server at the same time, so the BindToRenderStep process goes through. Unfortunately, such a trick will not work on a real server.
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
local ray = Ray.new(char.HumanoidRootPart.Position, sunDirection * sun_Detect)
local partFound = workspace:Raycast(ray.Origin, ray.Direction * 15, params)
if partFound then
safe = true
Safe()
else
safe = false
coolDown = math.max(0, coolDown - deltaTime)
if coolDown <= 0 then
if not burning and char.PlayerStats.SunImmunity.Value == false then
burning = false
BurnPlayer()
end
end
end
end)