Hello, Recently I've got into camera manipulation, and I've tried to make cutscenes, I've made one, with help of the wiki, which I do now understand.
But, my question is:
This cutscene plays when a player joins the server, how do I make it play when a player touches a certain part? I can't find any tutorials for this on the wiki, if anyone knows where to find them, then please link them to me!
-- localscript in starterGui local player = game.Players.LocalPlayer local TweenService = game:GetService("TweenService") local cam = workspace.CurrentCamera function play(char) local PP = char.PrimaryPart cam.CameraType = Enum.CameraType.Scriptable local BCFrame = PP.CFrame * CFrame.new(10,10,10) * CFrame.new(0,math.pi,0) local targetCFrame = PP.CFrame * CFrame.new(0, 0, -10) * CFrame.Angles(0, math.pi, 0) cam.CFrame = BCFrame local tween = TweenService:Create( cam, TweenInfo.new(2), {CFrame = targetCFrame} ) tween:Play() tween.Completed:Wait() cam.CameraType = Enum.CameraType.Custom end player.CharacterAdded:Connect(function(character) wait(3) play(game.Players.LocalPlayer.Character) end)
Thanks for your time
The CharacterAdded
event will automanically run whenever the player's Character
is loaded into the game. This is why it is running when the player joins.
Roblox has an event called Touched
. This event will run whenever an object
touches the part you set it to be. We can have this run for the part we want to be touched. It has one parameter, which is the object that touched the part. We will call this TouchPart
.
When doing a Touched
event, if you want an action to perform when a player touches it, you must check if the touchee is a player. Otherwise, your script will error.
-- localscript in starterGui local player = game.Players.LocalPlayer local TweenService = game:GetService("TweenService") local cam = workspace.CurrentCamera local TouchPart = game.Workspace.Part -- Change this to the part you want to be touched function play(char) local PP = char.PrimaryPart cam.CameraType = Enum.CameraType.Scriptable local BCFrame = PP.CFrame * CFrame.new(10,10,10) * CFrame.new(0,math.pi,0) local targetCFrame = PP.CFrame * CFrame.new(0, 0, -10) * CFrame.Angles(0, math.pi, 0) cam.CFrame = BCFrame local tween = TweenService:Create( cam, TweenInfo.new(2), {CFrame = targetCFrame} ) tween:Play() tween.Completed:Wait() cam.CameraType = Enum.CameraType.Custom end TouchPart.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then -- checking if the object that touched it is a player play(hit.Parent) -- plays the animation end end) -- This event below will run when the player is added. Delete it all if you do not want this! player.CharacterAdded:Connect(function(character) wait(3) play(game.Players.LocalPlayer.Character) end)