The problem is i want people who is in the range to see a lighting effect and the people not in the range will not see it.
local rp = game:GetService("ReplicatedStorage")
local World = rp:WaitForChild("TheWorldRemotes"):WaitForChild("World")
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local Color = rp:WaitForChild("TheWorldRemotes"):WaitForChild("Color")
local range = 100
local duration = 5
World.OnServerEvent:Connect(function(Player)
game.ServerScriptService.TheWorldServer.BarrageHold.TimeStop.Value = true
local Stand = workspace:FindFirstChild(Player.Name.." Stand"):WaitForChild("TheWorld")
if Stand then
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
local prevWeld = Stand:WaitForChild("HumanoidRootPart"):WaitForChild("Stand Weld")
prevWeld:Destroy()
Stand:WaitForChild("HumanoidRootPart").CFrame = HumanoidRP.CFrame * CFrame.new(0,-.5,-3)
local weld = Instance.new("ManualWeld")
weld.Name = "Stand Weld"
weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
weld.Part1 = HumanoidRP
weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * HumanoidRP.CFrame
weld.Parent = weld.Part0
local animControl = Stand:WaitForChild("AnimControl")
for i, track in pairs(animControl:GetPlayingAnimationTracks()) do
track:Stop()
end
local Spread = animControl:LoadAnimation(script.Spread)
Spread:Play()
local color = game.Lighting.ColorCorrection
local Folder = Instance.new("Folder",workspace)
Folder.Name = Player.Name.." The World"
local Orb = script.Orb:Clone()
Orb.CFrame = Stand:WaitForChild("HumanoidRootPart").CFrame
Orb.Orientation = Character:WaitForChild("HumanoidRootPart").Orientation
Orb.Parent = Folder
local goal = {}
goal.Size = Orb.Size + Vector3.new(50,50,50)
local info = TweenInfo.new(1,Enum.EasingStyle.Elastic,Enum.EasingDirection.InOut,0,false,.25)
local tween = TweenService:Create(Orb,info,goal)
tween:Play()
spawn(function()
wait(.5)
for i, chars in pairs(workspace:GetChildren()) do
if chars:FindFirstChild("Humanoid") then
if chars ~= Character then
local EHumanoidRP= chars:FindFirstChild("HumanoidRootPart")
if EHumanoidRP then
local distance = (HumanoidRP.CFrame.p - EHumanoidRP.CFrame.p).magnitude
if distance <= range then
spawn(function()
for j, k in pairs(chars:GetChildren()) do
if k:IsA("MeshPart") or k:IsA("Part") then
spawn(function()
k.Anchored = true
wait(duration)
k.Anchored = false
end)
end
end
end)
if distance <= range then -- this is where i need help i can'y figure it out and its not working at all
local player = game.Players:GetChildren()
if player == distance then
spawn(function()
game.Lighting.ColorCorrection.Enabled = true
wait(0.5)
game.Lighting.ColorCorrection.Enabled = false
game.Lighting.ColorCorrection2.Enabled = true
end)
end
end
end
end
end
local enemy = game.Players:GetPlayerFromCharacter(chars)
if enemy then
local Backpack = enemy:FindFirstChild("Backpack")
spawn(function()
for j, fold in pairs(Backpack:GetChildren()) do
if fold:IsA("Folder") then
local Enable = fold:FindFirstChild("Range")
spawn(function()
Enable.Value = true
wait(duration)
Enable.Value = false
end)
end
end
end)
end
end
end
end
end)
spawn(function()
wait(1)
local prevWeld = Stand:WaitForChild("HumanoidRootPart"):WaitForChild("Stand Weld")
prevWeld:Destroy()
Stand:WaitForChild("HumanoidRootPart").CFrame = HumanoidRP.CFrame * CFrame.new(2,0,2)
local weld = Instance.new("ManualWeld")
weld.Name = "Stand Weld"
weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
weld.Part1 = HumanoidRP
weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * HumanoidRP.CFrame
weld.Parent = weld.Part0
local Idle = animControl:LoadAnimation(script.Idle)
Idle:Play()
end)
wait(duration)
Debris:AddItem(Orb,1)
local goal2 = {}
goal2.Size = Orb.Size - Orb.Size
local info2 = TweenInfo.new(1,Enum.EasingStyle.Elastic,Enum.EasingDirection.InOut,0,false,.25)
local tween2 = TweenService:Create(Orb,info2,goal2)
tween2:Play()
color.Saturation = 0
game.ServerScriptService.TheWorldServer.BarrageHold.TimeStop.Value = false
World:FireClient(Player)
end
end)