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

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

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.

3 comments

0

I would change Camera.CameraSubject to Camera.CFrame = ________

0

Camera.CFrame = workspace.House1CameraPart.CFrame

0

Yeah, that's what I did, but that didn't work. :(

1 answer

✓ Accepted answer

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)

2 comments

0

Thank you bud! I can't believe it worked! Thanks for your cooperation man!

0

No problem :D

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