So im creating a game, a sorta adventure/obby game, and im trying to make it so the camera position changes when the trigger is touched for a little tutorial, but it just wont work and I have no idea why! Iv tried this in local and normal script. I have no idea if im just being stupid or i have its completly wrong. Any help will be appreciated iv tried fixing this issue for many days and im way too frustrated (name of the camera block is OrcCamera) code (in normal script in the trigger block):
local camera = workspace.Camera local cutcamera = workspace.OrcCamera script.Parent.OnTouched() workspace.Camera.CameraType = Enum.CameraType.Scriptable repeat wait() camera.CameraType = Enum.CameraType.Scriptable until camera.CameraType == Enum.CameraType.Scriptable camera.CFrame = cutcamera.CFrame script.Thud.Playing = true wait(3) script.Thud.Playing = false camera.CameraType = Enum.CameraType.Custom
Ok, I feel bad because the last 2 answers were just as wrong as your original code. Here is a working version of your script. We will need 2 scripts. A server and a local. Lets begin:
SETUP
1)Create a remote event under replicated storage
-Name it "PartTouched"
2)Create a server script under the part
3)Create a local script in StarterGui
4)Make sure you have a sound named "Thud" under the local script
SCRIPTING:
SERVER SCRIPT:
EV = game:GetService("ReplicatedStorage"):WaitForChild("PartTouched") script.Parent.Touched:Connect(function(obj) if not game.Players:GetPlayerFromCharacter(obj.Parent) then return end EV:FireClient(game.Players:GetPlayerFromCharacter(obj.Parent)) obj.Parent:MoveTo(obj.Position+Vector3.new(10,0,0)) --So it doesent keep activating end)
LOCAL SCRIPT:
local plrcam = workspace.CurrentCamera local cutcam = workspace.OrcCamera EV = game:GetService("ReplicatedStorage"):WaitForChild("PartTouched") local working = false --This acts as a debounce EV.OnClientEvent:Connect(function() if working == true then return end working = true plrcam.CameraType = enum.CameraType.Scriptable plrcam.CFrame = cutcam.CFrame script.Thud:Play() --You didnt do this right as you said "playing" wait(3) script.Thud:Stop() --Same here plrcam.CameraType = Enum.CameraType.Custom working = false end)
I hope I was able to help you out. With further questions/comments/concerns, feel free to respond to my answer. Happy scripting! ~mc3334
script.Parent.OnTouched()
is not a thing
script.Parent.Touched
is what your looking for
You would do this
local camera = workspace.Camera local cutcamera = workspace.OrcCamera local function moveCam() workspace.Camera.CameraType = Enum.CameraType.Scriptable repeat wait() camera.CameraType = Enum.CameraType.Scriptable until camera.CameraType == Enum.CameraType.Scriptable camera.CFrame = cutcamera.CFrame script.Thud.Playing = true wait(3) script.Thud.Playing = false camera.CameraType = Enum.CameraType.Custom end script.Parent.Touched:Connect(moveCam)
local cam = workspace.CurrentCamera function onTouched(hit) cam.CoordinateFrame = CFrame.new(--CFrame Here!) end script.Parent.Touched:Connect(onTouched)