Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont my trigger activate on touch?

Asked by 5 years ago

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

Log in to vote
0
Answered by
mc3334 649 Moderation Voter
5 years ago
Edited 5 years ago

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

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 stonez12345678910 4 — 5y
0
No problem! mc3334 649 — 5y
0
No problem! mc3334 649 — 5y
Ad
Log in to vote
-1
Answered by
cegberry 432 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
this does not work, the camera does change at all stonez12345678910 4 — 5y
0
can you show me the the hierarchy? cegberry 432 — 5y
0
hierarchy? no idea what that is stonez12345678910 4 — 5y
0
This wont work. You cant change the camera in a server script mc3334 649 — 5y
Log in to vote
-1
Answered by 5 years ago
local cam = workspace.CurrentCamera

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

0
does not work, and clearly you dont know how camera manipulation works stonez12345678910 4 — 5y
0
^ mc3334 649 — 5y
0
it worked for me i got it from roblox wiki User#28169 0 — 5y
0
Its outdated and CFrame is used, not CoordinateFrame. mc3334 649 — 5y

Answer this question