#Camera code not working

1 messages · Page 1 of 1 (latest)

midnight linden
#

This is a localscript that should, when working, allow the user to click on the click detector and look around from the CameraPart's position, for my horror game to check through the peephole. They also have the ability to press Q to go through the door. Neither of these are working. (yes ive tried AI, friends, other discords, dev forum, docs, etc)


local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local camera = Workspace.CurrentCamera
local door = Workspace.DoorSystemByBlaze.Door2
local knob = door.Knob
local clickDetector = knob:FindFirstChild("ClickDetector")
local destination = door.Destination
local cameraPart = door.Camera
local canTeleport = false

clickDetector.MouseClick:Connect(function(clickingPlayer)
    if clickingPlayer ~= player then return end
    canTeleport = true
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = CFrame.new(cameraPart.Position, cameraPart.Position + cameraPart.CFrame.LookVector)
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed or not canTeleport then return end
    if input.KeyCode == Enum.KeyCode.Q then
        local character = player.Character
        if character then
            local hrp = character:FindFirstChild("HumanoidRootPart")
            if hrp then
                hrp.CFrame = destination.CFrame + Vector3.new(0, 3, 0)
            end
        end
        camera.CameraType = Enum.CameraType.Custom
        canTeleport = false
    end
end)

player.CharacterAdded:Connect(function()
    camera.CameraType = Enum.CameraType.Custom
    canTeleport = false
end)
hushed sparrow
#

does it do nothing

#

does it do the wrong thing

#

does it error

midnight linden
#

it does nothing

#

it just

#

like

#

decides it doesnt wanna work

#

i added tests like print statements, the only one that actually runs is test 0, which is at line 1

midnight linden
hushed sparrow
#

game:GetService("Workspace") 🥀

#

does the clickdetector click?

#

have you checked that?

midnight linden
#

yes

#

ut kidna doesnt

#

uh actually

midnight linden
midnight linden
hushed sparrow
#

so focus on that

midnight linden
#

print("test 0")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera


local door = workspace:WaitForChild("DoorSystemByBlaze"):WaitForChild("Door2")
local knob = door:WaitForChild("Knob")
local clickDetector = knob:WaitForChild("ClickDetector")
local destination = door:WaitForChild("Destination")
local cameraPart = door:WaitForChild("Camera")

local canTeleport = false


clickDetector.MouseClick:Connect(function(clickingPlayer)
    print('test 0.5')
    if clickingPlayer ~= player then return end

    canTeleport = true
    print("Test 1")

    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = CFrame.new(cameraPart.Position, cameraPart.Position + cameraPart.CFrame.LookVector)

    print("Test 2")
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed or not canTeleport then return end

    if input.KeyCode == Enum.KeyCode.Q then
        print("Test 3")

        local character = player.Character or player.CharacterAdded:Wait()
        local hrp = character:FindFirstChild("HumanoidRootPart")
        if hrp then
            hrp.CFrame = destination.CFrame + Vector3.new(0, 3, 0)
            print("Test 4")
        end

        camera.CameraType = Enum.CameraType.Custom
        canTeleport = false
    end
end)


player.CharacterAdded:Connect(function()
    print("Test 5")
    camera.CameraType = Enum.CameraType.Custom
    canTeleport = false
    print("Test 6")
end)

This is basically the same kinda just with some edited stuff and tests

midnight linden
#

for the last

#

two days

hushed sparrow
#

you have lots of waitforchilds

#

have you checked that all of them get fulfilled

midnight linden
#

yes ik

#

im

hushed sparrow
#

and the connections get made

midnight linden
#

im gonna directly reference

#

\see what the difference is

hushed sparrow
#

no

#

on client that's not a bad idea

midnight linden
#

its a localscript

hushed sparrow
#

but the point of WaitForChild is that it waits until the child gets added

midnight linden
#

its useless unless referring to something in replicatedfirst as that is the only thing where it loads before everything else

#

like

#

evferything else loads

#

before running code

#

haha

#

well

#

it gets to test 2

#

now that i dont directly reference

#

and actually going through the door works

#

however

#

the camera thing doesnt

#

the peeophole

#

gets to test 4

hushed sparrow
midnight linden
#

actually

hushed sparrow
#

(enabled by default)

midnight linden
#

streaming enabled is off

#

alright so, the camera thing kidna works but for a brief second only, after that brief milisecond or so, the camera returns to the player

arctic jackal
#

have you fixed this or no

#

shouldve just been a simple task.wait() just before the cameratype returns to custom as far as i can tell

midnight linden
#

no

midnight linden
#

yeah its not working

#

print("test 0")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera


local door = workspace:WaitForChild("DoorSystemByBlaze"):WaitForChild("Door2")
local knob = door:WaitForChild("Knob")
local clickDetector = knob.DoorBlank
local destination = door.Destination
local cameraPart = door.Camera

local canTeleport = false


clickDetector.MouseClick:Connect(function(clickingPlayer)
    print('test 0.5')
    if clickingPlayer ~= player then return end

    canTeleport = true
    print("Test 1")

    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = CFrame.new(cameraPart.Position, cameraPart.Position + cameraPart.CFrame.LookVector)
    task.wait(5)
    camera.CameraType = Enum.CameraType.Custom

    print("Test 2")
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed or not canTeleport then return end

    if input.KeyCode == Enum.KeyCode.Q then
        print("Test 3")

        local character = player.Character or player.CharacterAdded:Wait()
        local hrp = character:FindFirstChild("HumanoidRootPart")
        if hrp then
            hrp.CFrame = destination.CFrame + Vector3.new(0, 3, 0)
            print("Test 4")
        end

        camera.CameraType = Enum.CameraType.Custom
        canTeleport = false
    end
end)


player.CharacterAdded:Connect(function()
    print("Test 5")
    camera.CameraType = Enum.CameraType.Custom
    canTeleport = false
    print("Test 6")
end)

arctic jackal
#

did anything change at all or no

midnight linden
#

now the actually going through the door doesnt work like when u press q ur supposed to enter but now that doesnt work either

arctic jackal
#

😭 oh dear

midnight linden
#

ikr

arctic jackal
#

oh

#

my fault

midnight linden
#

i got it to kinda fix itself by using direct references the first time and that got the enter working, adding the task.wait broke the whole thing

#

what

arctic jackal
#

yeah put the task wait

midnight linden
#

where

#

im kinda

#

stupid

arctic jackal
#

just agter print 4

midnight linden
#

k

#

hold on lemem try

arctic jackal
#

just after that print 4 end is where we want task wait, it should keep the camera on the door

#

should

midnight linden
#

wait

#

lemme delete acs rq

#

nvm

#

didnt work

#

im using Saude

#

idk if that will affect anything

#

uh

#

ok now its not working at all

#

nope

#

still not working

#

damn

arctic jackal
#

hold up, show the code

midnight linden
#

print("test 0")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera


local door = workspace:WaitForChild("DoorSystemByBlaze"):WaitForChild("Door2")
local knob = door:WaitForChild("Knob")
local clickDetector = knob.DoorBlank
local destination = door.Destination
local cameraPart = door.Camera

local canTeleport = false


clickDetector.MouseClick:Connect(function(clickingPlayer)
    print('test 0.5')
    if clickingPlayer ~= player then return end

    canTeleport = true
    print("Test 1")

    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = CFrame.new(cameraPart.Position, cameraPart.Position + cameraPart.CFrame.LookVector)

    print("Test 2")
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed or not canTeleport then return end

    if input.KeyCode == Enum.KeyCode.Q then
        print("Test 3")

        local character = player.Character or player.CharacterAdded:Wait()
        local hrp = character:FindFirstChild("HumanoidRootPart")
        if hrp then
            hrp.CFrame = destination.CFrame + Vector3.new(0, 3, 0)
            print("Test 4")
            task.wait(5)
        end

        camera.CameraType = Enum.CameraType.Custom
        canTeleport = false
    end
end)


player.CharacterAdded:Connect(function()
    print("Test 5")
    camera.CameraType = Enum.CameraType.Custom
    canTeleport = false
    print("Test 6")
end)

arctic jackal
#

ok and 1 more time overall what do we want this to do

#

also do you want the camera coming back to the player to be auto or keybound

midnight linden
#

ok so: clicking on the click detector allows your camera to be set to the position of the "Camera" part, acting as a peephole. Pressing Q teleports the player inside, simulating entering

arctic jackal
#

ok

#

just to make sure is this in a local script in starterplayerscripts

midnight linden
#

k

arctic jackal
#

its a question

midnight linden
#

it was in startercharcter scripts but now when i put it in starterplayerscripts my camera is just like in a baseplate and i cant move or anything

arctic jackal
#

hmmmm ok

midnight linden
#

i think one of my idiot devs

#

put it in

#

scs

#

im the hdev

#

rn

#

so

#

im boutta

#

crash out

#

wait nvm

#

im just impatient

#

alr so the enter the door thing works, but now teh camera is doing that same thing

#

changes for 1 ms

#

and then

#

goes back

#

let me try deleting saude again

arctic jackal
#

ok try putting the taskwait just after that end instead of before

#

the print 4 end

midnight linden
#

it is after

#

uh

#

hold

arctic jackal
#

also increase the time slightly just so we can see if there is difference

midnight linden
#

alr its 7

arctic jackal
#

hmmmm

midnight linden
#

oh wait

arctic jackal
#

really we just need a line of code that freezes the script for a few seconds so the camera doesnt move back to the player

midnight linden
#

im stupido

arctic jackal
#

whats up

midnight linden
#

the third line

#

lemem try making it scriptable

arctic jackal
#

hmmm

midnight linden
#

balls

#

nope

#

doesnt work

arctic jackal
#

i think that is default

#

yeah

midnight linden
#

yeah

arctic jackal
#

we just need script to hold for a few seconds just after print4

#

hmmm

#

give me a minute

midnight linden
#

alr

arctic jackal
#

hmmmm

#

add this real quick just to check something

midnight linden
#

add what

arctic jackal
#

UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed or not canTeleport then return end

if input.KeyCode == Enum.KeyCode.E then
    print("Test 3")
#

camera.CameraType = Enum.CameraType.Custom
canTeleport = false

midnight linden
#

changing the keycode?

arctic jackal
#

no

#

adding a 2nd keycode to revert camera back to normal after the door

midnight linden
#

ok

arctic jackal
#

hmm no cause its not holding anyways

#

bro

#

wtf

midnight linden
#

EXACT LY

#

atp

#

its a roblox studio bug

arctic jackal
#

hey, let me know if you find a way to fix it or just do away with it for something else, im gonna keep trying to figure this out for a little bit

#

also, have you already tried adding a camera to the part and just having the players camera switch to that camera on button prompt?

night domeBOT
#

studio** You are now Level 5! **studio

midnight linden
#

fuck it

#

im going to unity

hazy fern
#

the camera resets instantly after clicking on the door?

#

looks like it should work in starterplayerscripts