Lua 设定人形行走速度
我在一个类似的问题中发现了这个脚本,但是,我得到了错误Lua 设定人形行走速度,lua,roblox,Lua,Roblox,我在一个类似的问题中发现了这个脚本,但是,我得到了错误16:11:18.560-Workspace。脚本:2:尝试用“Character”索引nil local Player = game:GetService("Players").LocalPlayer local character = Player.Character or Player.CharacterAdded:Wait() local HumanoidRootPart = character:WaitForChild("Human
16:11:18.560-Workspace。脚本:2:尝试用“Character”索引nil
local Player = game:GetService("Players").LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
-- setting speed
local Humanoid = character:WaitForChild("Humanoid")
if Humanoid then
Humanoid.WalkSpeed = 25
end
有人能帮我吗?LocalPlayer对象只存在于LocalScript中。这就是变量
Player
为零的原因
有两种方法可以解决此问题:
1) 将此代码移到本地脚本中,或
2) 将此代码添加到当玩家加入游戏时执行的回调中。下面是它的样子
local PlayerService = game:GetService("Players")
-- wait for a player to join the game
PlayerService.PlayerAdded:Connect( function(Player)
-- wait for the player's character to load
Player.CharacterAdded:Connect( function(Character)
-- set the speed
local Humanoid = Character:WaitForChild("Humanoid")
if Humanoid then
Humanoid.WalkSpeed = 25
end
end)
end)
这是本地脚本还是服务器脚本?@Kylaaa在服务器脚本中