You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

报错“Text is not a valid member of Frame”,Roblox滑块脚本如何修复?

问题解决:"Text is not a valid member of Frame" 错误及滑块显示逻辑修复

核心问题解析

  1. 控件类型错误
    错误提示明确说明你调用 Text 属性的对象是 Frame,但 Frame 没有 Text 属性。你的变量 WalkSpeedDisplay = SliderFrame.WalkSpeedNum 指向的是一个Frame控件,而非用于显示文本的 TextLabel 或 TextBox。

  2. 显示逻辑错误
    你当前用 game.StarterPlayer.CharacterWalkSpeed 作为显示值,这是角色的初始默认移动速度,并非滑块调节后的实时速度,所以即使控件类型正确,显示内容也不会随滑块变化。

修复步骤

步骤1:修正UI控件类型

在Roblox Studio中找到 SliderFrame 下的 WalkSpeedNum 对象:

  • 将其类型从 Frame 改为 TextLabel(仅用于显示推荐用这个)或 TextBox。
  • 确保对象名称正确无误,脚本能正确引用到它。

步骤2:修正脚本逻辑

修改脚本中的两处问题:

  • 删除重复定义的 local SliderFrame = script.Parent.WalkSpeedSlider(后面重新定义了一次,重复变量无意义)。
  • 替换显示值为滑块调节后的实际移动速度,而非默认值。
  • 增加Humanoid空值判断,避免角色未加载时出错。

修复后的完整代码

--SLIDER:
local UIS = game:GetService("UserInputService")
local WalkSpeedSlider = script.Parent.WalkSpeedSlider

local SliderFrame = WalkSpeedSlider.SliderFrame
local Slider = SliderFrame.Slider
local WalkspeedReset = SliderFrame.Reset
local WalkspeedDragging = false
local WalkSpeedDisplay = SliderFrame.WalkSpeedNum -- 确保这个对象是TextLabel/TextBox

Slider.MouseButton1Down:Connect(function()
    WalkspeedDragging = true
end)

UIS.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        WalkspeedDragging = false
    end
end)

UIS.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseMovement and WalkspeedDragging then
        local MouseL = UIS:GetMouseLocation()
        local RelativePos = MouseL - SliderFrame.AbsolutePosition
        local percent = math.clamp(RelativePos.X / SliderFrame.AbsoluteSize.X, 0, 1)
        Slider.Position = UDim2.new(percent, 0, 0, 0)
        
        -- 获取当前玩家的Humanoid并修改移动速度
        local humanoid = game.Players.LocalPlayer.Character:FindFirstChildWhichIsA("Humanoid")
        if humanoid then
            local newWalkSpeed = math.round(percent * 120)
            humanoid.WalkSpeed = newWalkSpeed
            -- 用实际修改后的速度更新显示
            WalkSpeedDisplay.Text = tostring(newWalkSpeed)
        end
    end
end)

额外提示

  • 调试时可以用 print(typeof(WalkSpeedDisplay)) 确认控件类型,确保是TextLabel/TextBox。
  • 如果需要保留初始值重置功能,可以在 WalkspeedReset 的点击事件中恢复Humanoid的WalkSpeed为 game.StarterPlayer.CharacterWalkSpeed,并同步更新显示。

内容的提问来源于stack exchange,提问作者Mighty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 14:15:28