I need help with my script

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)

This is not possible to my knowledge, pretty sure lightning is replicated to all clients, so you can’t enable it for only one person. I think.

no its not becuase if do a local test of two player and change the lighting it will change for onne player

Could you use :toObjectSpace? That shows the distance between a basepart and another part. It treats the basepart as the center of the game.

Also, put this on client side because server sided requests appear to all players. You could use remote events to fix this problem if you wish to keep using server side.

how should i put it on client side if i need to first get the players and then fireclient()

Can you explain that a little more clearer. It is kind of confusing.

So you know how i got the player anchored when in range it but know i have to do the same but get players but how should i get players so i can do a client event

Well you could add a BoolValue named “IsPlayer” to the character. Then:

for i,v in pairs (game.Workspace:GetChildren()) do
      if v:FindFirstChild("IsPlayer") then
local character = v
end
end

Thats getting all the characters and looping through all the players characters.

1 Like

This will work then i can do the color thx

Happy to help! Hope your game goes well!

1 Like