StarterCharacterScript (啟動角色腳本)

StarterCharacterScripts 是一個容器,用於保存會在每個玩家生成角色模型時自動添加的腳本。

此處的腳本通常用於修改玩家的角色,例如更改移動機制、添加特殊能力或修改角色的外觀和行為。

-- StarterCharacterScripts > CustomJumpScript

local ContentProvider = game:GetService("ContentProvider")

local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")

	local jumpAnimation = Instance.new("Animation")
	jumpAnimation.AnimationId = "rbxassetid://97611958527430"

	-- Preload the animation to check if it exists
	local success, errorMessage = pcall(function()
		ContentProvider:PreloadAsync({jumpAnimation})
	end)

	if success then
		print("Animation asset exists and has been preloaded successfully.")

		local animationTrack = humanoid:LoadAnimation(jumpAnimation)
		animationTrack.Priority = Enum.AnimationPriority.Action  -- Set the priority on the AnimationTrack

		local function playCustomJump()
			animationTrack:Play()
		end

		humanoid.Jumping:Connect(playCustomJump)

	else
		warn("Failed to load animation asset: " .. errorMessage)
	end
end

local player = game.Players.LocalPlayer
player.CharacterAdded:Connect(onCharacterAdded)

if player.Character then
	onCharacterAdded(player.Character)
end

如果你覺得這個教程對你有幫助,並且願意支持我的工作,請考慮請我飲杯咖啡。

非常感謝你的支持!

請我飲杯咖啡