Local effect plays for everyone in the server instead of the client

I’m trying to make an effect for when someone is touching a part, by making the fog and ambient in Lighting have different values, however if one person touches this part, the effect plays for everyone in the server.

The script is located in StarterPlayerScripts, and uses a 2nd script and a BindableEvent both parented to the same script.

I’ve tried switching the original script location somewhere like StarterGui but the effect keeps playing for everyone.

Scripts:
Script 1 (main script for the effect)

local Music = workspace.Music:GetChildren() -- normal game music
local otherMusic = workspace.OtherMusic

local currentSong = game.ReplicatedStorage.CurrentSong

local randSound = nil
local prevSound = nil

local in700m = false

script["700m"].Event:Connect(function(bool)
	in700m = bool
	if in700m then
		for i, v in pairs(workspace.Music:GetChildren()) do
			v.Volume = 0 -- muting normal music
		end
		game.Lighting.FogColor = Color3.fromRGB(255, 85, 0)
		game.Lighting.FogEnd = 150
		game.Lighting.ClockTime = 0
		game.Lighting.OutdoorAmbient = Color3.fromRGB(255, 0, 0)
		otherMusic["700mMusic"]:Play()
	else
		for i, v in pairs(workspace.Music:GetChildren()) do
			v.Volume = 1 -- unmuting normal music
		end
		game.Lighting.FogColor = Color3.fromRGB(255, 255, 255)
		game.Lighting.FogEnd = 500
		game.Lighting.ClockTime = 14.5
		game.Lighting.OutdoorAmbient = Color3.fromRGB(70,70,70)
		otherMusic["700mMusic"]:Stop()
	end
end)

Script 2 (detecting when the player touches the hitbox)

local region = workspace["700mRegion"]
local event = script.Parent["700m"]

region.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		event:Fire(true)
	end
end)

region.TouchEnded:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		event:Fire(false)
	end
end)

you would be looking at a RemoteEvent to fire for a Specific Player, or the Client by itself to detect the Touched event, keep in mind that when you create a Touched Event on the Client for a Player, it will do this for all Players that exist in the game, and since Touched Detects anything that touches it, it will fire for all Players who have this event connected for their client.

Thank you, I converted the checker to a server script and make the event a RemoteEvent and now it works.

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