Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wont my trigger activate on touch?

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

3 answers

✓ Accepted answer

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

3 comments

0

This worked perfectly, thank you so much, been stuck on this for so many days and couldnt make any more advancments, so thank you so much

0

No problem!

0

No problem!

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)

4 comments

0

this does not work, the camera does change at all

0

can you show me the the hierarchy?

0

hierarchy? no idea what that is

0

This wont work. You cant change the camera in a server script

local cam = workspace.CurrentCamera

function onTouched(hit)
	cam.CoordinateFrame = CFrame.new(--CFrame Here!)
end
script.Parent.Touched:Connect(onTouched)

4 comments

0

does not work, and clearly you dont know how camera manipulation works

0

^

0

it worked for me i got it from roblox wiki

0

Its outdated and CFrame is used, not CoordinateFrame.

This discussion is preserved as it was. New answers, comments, and votes are closed.