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

[SOLVED] Why is the Camera's CFrame not setting to a part?

Asked by 5 years ago
Edited 5 years ago

Hello. I am working on a script where a player touches a part, then the camera would be set to a different part.

Here's my script

local CanHit = true

local Camera = workspace.CurrentCamera

script.Parent.Touched:Connect(function(hit)
    local h = hit.Parent:FindFirstChild('Humanoid')
    if h then
        local player = game.Players[hit.Parent.Name]
        if player:FindFirstChild('PlayerGui') then
            if CanHit == true then
                CanHit = false
                        player.PlayerGui.BlackGui.Frame:TweenSize(UDim2.new(1,0,2,0),'In','Linear',.1)
                wait(1)
                Camera.CameraType = "Scriptable"
                Camera.CameraSubject = workspace.House1CameraPart
                hit.Parent:FindFirstChild('HumanoidRootPart').CFrame = CFrame.new(-146.816, 3, -58.368)
                wait(1)
                player.PlayerGui.BlackGui.Frame:TweenSize(UDim2.new(1,0,1,0),'In','Linear',.1)
                CanHit = true
            end
        end
    end
end)

Yea, um. The format is sorta broken, but I hope you can still read it. Any help please? I believe it may the something related with ROBLOX studio.

0
I would change Camera.CameraSubject to Camera.CFrame = ________ fighterkirbyzx 102 — 5y
0
Camera.CFrame = workspace.House1CameraPart.CFrame fighterkirbyzx 102 — 5y
0
Yeah, that's what I did, but that didn't work. :( Sensei_Developer 298 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

The problem is that a script cant access the PlayerGui, and it can't access the camera, so we use a RemoteEvent to send it over to the client.

There needs to be 1 RemoteEvent in ReplicatedStorage named "TweenGui"

Script:

local CanHit = true

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("HandleClient")

script.Parent.Touched:Connect(function(hit)
    local h = hit.Parent:FindFirstChild('Humanoid')
    if h then
        local player = game.Players[hit.Parent.Name]
        if CanHit == true then
            CanHit = false
        RemoteEvent:FireClient(player) --Fires it to the client.
            wait(1)
            hit.Parent:FindFirstChild('HumanoidRootPart').CFrame = CFrame.new(-146.816, 3, -58.368)
            wait(1)
            CanHit = true
        end
    end
end)

LocalScript In BlackGui:

local BlackGui = script.Parent
local Frame = BlackGui:WaitForChild("Frame")

local Camera = workspace.CurrentCamera

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("HandleClient")

RemoteEvent.OnClientEvent:Connect(function()
    Frame:TweenSize(UDim2.new(1,0,2,0),'In','Linear',.1)
    wait(1)
    Camera.CameraType = "Scriptable"
    Camera.CameraSubject = workspace.House1CameraPart
    wait(1)
    Frame:TweenSize(UDim2.new(1,0,1,0),'In','Linear',.1)
end)
0
Thank you bud! I can't believe it worked! Thanks for your cooperation man! Sensei_Developer 298 — 5y
0
No problem :D firestarroblox123 440 — 5y
Ad

Answer this question