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.
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)