Need help figuring out how to make this first person animation work

  1. What do you want to achieve? I want to make it so a first person animation plays when a player touches a part getting teleported to the first part that plays the animation, and the camera being attached to the player’s head until the animation stops then the player being teleported to another part to end the animation and the camera being back to normal.

  2. What is the issue? I can’t seem to figure out how to do it the script won’t work at all, I have been struggling with it for the past weeks, I am very new at scripting etc

  3. What solutions have you tried so far? I have looked everywhere and I have never seen anyone talk about it before, I am so clueless at this point since i have seen other games do something similar to that and noone talking about something like this as if its self explanatory.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Cam = game.Workspace.CurrentCamera
local animationpart = script.Parent:WaitForChild("AnimationPart")
local teleportpart = script.Parent:WaitForChild("TeleportPart")
local humanoid = Character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")


script.Parent.Touched:Connect(function()
	Cam.CameraType = Enum.CameraType.Scriptable
	Character:MoveTo(animationpart.Position)
	local anim = Instance.new("Animation")
	anim.AnimationId = "rbxassetid://12205528065"
	local track = animator:LoadAnimation(anim)
	track:Play()
	print("Working")
	
	if track.Stopped then
		Character:MoveTo(teleportpart.Position)
		Cam.CameraType = Enum.CameraType.Custom
	end
end)

I have put this as a localscript inside the part

If anyone could help me figure out how to do this I would really appreciate it, I am very new in this whole scripting scene.

2 Likes

Can you describe what happened when you started to run script?

The script should trigger as soon as I touch the part but it doesn’t trigger at all, I put a print in the script, and it won’t print either

I think I know what the issue of your code is
Instead of using if Animation.Stopped then bla bla, you should use .Stopped:Wait() or .Ended:Wait()

if track.Stopped:Wait() then
		Character:MoveTo(teleportpart.Position)
		Cam.CameraSubject = Enum.CameraType.Custom

I made it like this now but the script still won’t trigger

Nah, you used it wrongly. Event:Wait() pauses the script until the event fires.

you cant use if statement on track.Stopped:Wait()

So would having this work instead

track.Ended:Wait()
		Character:MoveTo(teleportpart.Position)
		Cam.CameraType = Enum.CameraType.Custom

maybe it will work
if it doesn’t work, please show me output

Unfortunately, BasePart.Touched does not fire in local scripts when you touch the BasePart. You’d have to use another method, raycasting might work, I tried using this in a local script and it work wonderfully.

Also, you shouldn’t parent local scripts under workspace as a descendant as local scripts don’t run in workspace.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.