Yet another scripting question for my game

local RunService = game:GetService('RunService')

local CameraManipulated = false

workspace.PartToTouch.Touched:Connect(function(hit)
	if game.Players.LocalPlayer == game.Players:GetPlayerFromCharacter(hit.Parent) then
		CameraManipulated = true
	end
end)

workspace.RemoveCamera.Touched:Connect(function(hit)
	if game.Players.LocalPlayer == game.Players:GetPlayerFromCharacter(hit.Parent) then
		CameraManipulated = false
	end
end)


RunService.RenderStepped:Connect(function()
	if CameraManipulated then
		workspace.CurrentCamera.CFrame = workspace.CameraPart.CFrame
	end
end)

its not my script and i don’t remember where i got it, but in the game there’s a localscript in the startercharacterscripts that teleports the camera when you touch a brick and returns it to normal when you touch another. it has a problem where it works when you spawn close to it, but ceases working at random



above is the script working
below is the script not working

im not sure if it has anything to do with filtering enabled, different scripts messing with each other or if its just technology being stupid for the 40192384th time

Heres a better version:

local part = -- Part to be touched
local cameraPart = -- The camera Part

local touching = false

local camera = workspace.CurrentCamera

part.Touched:Connect(function(otherPart)
	if otherPart.Parent:FindFirstChildOfClass("Humanoid") and not touching then
		touching = true
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = cameraPart.CFrame
	end
end)

part.TouchEnded:Connect(function(otherPart)
	if otherPart.Parent:FindFirstChildOfClass("Humanoid") and touching then
		touching = false
		camera.CameraType = Enum.CameraType.Custom
	end
end)

Still this might not be the best, and it requires only one part, but test it out, it should be more consistent.

ok i’ve discovered that streamingenabled seems to be the reason it didn’t work properly.
oh yeah and its called streamingenabled not filteringenabled oops

1 Like