【问题标题】:Animation issue on Roblox StudioRoblox Studio 的动画问题
【发布时间】:2022-12-21 02:57:10
【问题描述】:

我制作了一个为玩家触发动画的按钮,但它只对我有用。我的朋友说她可以按下按钮,但动画没有激活。我只是使用了proximty prompt上的指南。有人告诉我这与本地文字无关,所以我现在很茫然

下面的脚本位于 StarterPlayer > StarterPlayerScripts 下

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:Wait()
end

local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")

local shockButton = workspace.ShockButton.Button
local proximityPrompt = shockButton.ProximityPrompt

local shockAnimation = Instance.new("Animation")
shockAnimation.AnimationId = "rbxassetid://9349455501"

local shockAnimationTrack = Animator:LoadAnimation(shockAnimation)

shockAnimationTrack.Priority = Enum.AnimationPriority.Action
shockAnimationTrack.Looped = false

local function onShockTrigger(player)
    
    shockAnimationTrack:Play()
    humanoid.WalkSpeed = 0
    shockAnimationTrack.Stopped:Wait()
    humanoid.WalkSpeed = 16
end

proximityPrompt.Triggered:Connect(onShockTrigger)

【问题讨论】:

  • 为什么没人回答?

标签: lua roblox


【解决方案1】:

问题不在于您的代码,而在于它所在的位置。在 LocalScripts 中对世界所做的更改不会复制到其他玩家,它们只会显示给该玩家。因此,因为您要让动画在 LocalScript 中播放,所以只有那个玩家可以看到动画。

简单的解决方法是将动画代码移动到服务器脚本中,然后将脚本移动到 ServerScriptService 或工作区中。 ProximityPrompts 会告诉您哪个玩家与之交互,因此您可以基于此找到玩家的角色模型。

local shockButton = workspace.ShockButton.Button
local proximityPrompt = shockButton.ProximityPrompt

local shockAnimation = Instance.new("Animation")
shockAnimation.AnimationId = "rbxassetid://9349455501"

local function onShockTrigger(player)
    -- get the animator
    local character = player.Character
    if not character or not character.Parent then
        character = player.CharacterAdded:Wait()
    end
    local humanoid = character:WaitForChild("Humanoid")
    local Animator = humanoid:WaitForChild("Animator")

    -- configure the animation
    local shockAnimationTrack = Animator:LoadAnimation(shockAnimation)
    shockAnimationTrack.Priority = Enum.AnimationPriority.Action
    shockAnimationTrack.Looped = false

    -- play the animation
    shockAnimationTrack:Play()
    humanoid.WalkSpeed = 0
    shockAnimationTrack.Stopped:Wait()
    humanoid.WalkSpeed = 16
end

proximityPrompt.Triggered:Connect(onShockTrigger)

【讨论】:

    【解决方案2】:

    他说当他的朋友激活动画时,他没有,顺便说一句,我也有同样的问题,我用我自己的替换了自定义动画(跑步,空闲,跳跃等),我在roblox中发布了这些动画,但显然只有我可以访问它们,其他人看不到他们自己的,逻辑上其他人看不到,而我看到我的和其他人

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 2021-11-12
      • 2021-12-27
      • 2018-12-01
      • 2020-08-19
      • 2020-10-27
      • 2021-11-24
      • 2023-02-18
      • 2021-10-16
      相关资源
      最近更新 更多