Local script visible to all players

My local script is inside of the startercharacter folder but when i touch a door that was scripted inside of the local script its visible to all players

i have tried to look online but i couldnt find anything

Please help!

Heres the script

local TS = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local humanoid = script.Parent:WaitForChild("Humanoid")
local hrp = script.Parent:WaitForChild("HumanoidRootPart")

local level = workspace:WaitForChild("Level")
local objs = level:WaitForChild("Objects")
script.Parent:SetAttribute("Water", false)


for Index, Object in objs:GetDescendants() do 
	if Object:IsA("BasePart") then 
		if Object.Name == "Fade" then
			Object.Touched:Connect(function()
				if Object:WaitForChild("db").Value == 0 then
				local targetProperties = {}
				targetProperties.Transparency = 1
					Object:WaitForChild("db").Value = 1
					local disappearFade = TS:Create(Object, TweenInfo.new(Object.Time.ReTime.Value), targetProperties)
				disappearFade:Play()
					task.delay(Object.Time.Value,function()
						Object.CanCollide = false
						Object.CanTouch = false
				end)
				disappearFade.Completed:Wait()
					task.delay(Object.Time.ReTime.Value, function()
						Object:WaitForChild("db").Value = 0
						Object.Transparency = 0
						Object.CanCollide = true
						Object.CanTouch = true
				   end)
				end
			end)
		end
	end
end

for Index, Object in objs:GetDescendants() do 
	if Object:IsA("Model") then 
		if Object.Name == "canon" then
			------
			local function ease(v:number)
				return v
			end

			local function launch(from:Vector3, to:Vector3, speed:number)
				local timeToTake = (from-to).Magnitude/speed
				local timeElapsed = 0

				local playerRoot = script.Parent.PrimaryPart
				playerRoot.Anchored = true

				local con con = RunService.RenderStepped:Connect(function(dt)
					timeElapsed = math.min(timeElapsed + dt, timeToTake)

					local p = timeElapsed/timeToTake
					local YOffset = math.sin(p * math.pi) * 20
					playerRoot.CFrame = CFrame.new(from:Lerp(to, p) + Vector3.new(0, YOffset, 0))
					
					if timeElapsed == timeToTake then
						print("and we're done!")
						con:Disconnect()
						playerRoot.Anchored = false
					end
				end)
			end
			------
			Object:WaitForChild("PartA").Touched:Connect(function()
				if Object.db.Value == 0 then
					Object.db.Value = 1
					launch(Object.PartA.Position, Object.PartB.Position, 60)

				task.delay(2,function()
						Object.db.Value = 0
				end)
				end
			end)
		elseif Object.Name == "Door" then
			Object:WaitForChild("HitBox").Touched:Connect(function()
				if Object:GetAttribute("active") == false then
					if Object:FindFirstChild("Water") == nil then
						local door = Object:WaitForChild("door")
						Object:WaitForChild("neon").Color = Color3.fromRGB(75, 255, 96)
				local targetProperties = {}
					targetProperties.CFrame = door:WaitForChild("door").CFrame
						local open = TS:Create(door, TweenInfo.new(Object.time.Value), targetProperties)
				open:Play()
						Object:SetAttribute("active", true)
					elseif Object:FindFirstChild("Water") ~= nil then
					task.delay(3,function()
							local water = Object.Water.Value
							local new = Object["new)Water"].Value
						print(water.Position)
						
						local A = {}
						A.CFrame = new.CFrame
						A.Size = new.Size
							local E = TS:Create(water, TweenInfo.new(Object:WaitForChild("watert").Value), A)
						E:Play()
						end)
						
						local door = Object:WaitForChild("door")
						Object:WaitForChild("neon").Color = Color3.fromRGB(75, 255, 96)
						local targetProperties = {}
						targetProperties.CFrame = door:WaitForChild("door").CFrame
						local open = TS:Create(door, TweenInfo.new(Object.time.Value), targetProperties)
						open:Play()
						Object:SetAttribute("active", true)
				end
				end
			end)
		elseif Object.Name == "Tp" then
			Object:WaitForChild("HitBox").Touched:Connect(function()
				if Object:GetAttribute("activated") == false then
					hrp.Position = Object:WaitForChild("next"):WaitForChild("TP").Position
					Object:SetAttribute("activated", true)
					local neon = Object:WaitForChild("neon")
					local targetProperties = {}
					targetProperties.Color =Color3.fromRGB(255, 0, 0)
					local open = TS:Create(neon, TweenInfo.new(1), targetProperties)
					open:Play()
					task.delay(2,function()
						local t = {}
						t.Color =Color3.fromRGB(255, 255, 255)
						local e = TS:Create(neon, TweenInfo.new(1), t)
						e:Play()
						Object:SetAttribute("activated", false)
					end)
				end
			end)
		end
	end
end

Even if its a local script, physics still replicates automatically which triggers other peoples local script.

This should be related to your problem:

Thank you so much, I was really confused as to why this was happening turns out I forgot to check if hit.parent == plr

1 Like

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