【发布时间】:2019-01-08 08:51:14
【问题描述】:
我正在制作一个用于 ProtoSmasher 的飞行脚本,但它没有按预期工作。我希望它有一个切换按钮(G),然后能够用一个按钮(W)飞行。取而代之的是,要让它工作,我必须按住 W 然后按 G;但如果我试图放开 w 以停在空中,我必须再次按 G。
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character
local hum = char.Humanoid
local Torso = char.HumanoidRootPart
local Mouse = plr:GetMouse()
local toggle = false
local wToggle = false
Mouse.KeyDown:Connect(function(key)
if key == "w" then
wToggle = true
end
if key == "g" then
if toggle == false then
toggle = true
local BV = Instance.new("BodyVelocity",Torso)
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
while wToggle == true do
BV.Velocity = Mouse.Hit.lookVector*200
wait()
end
end
if toggle == true then
toggle = false
Torso:FindFirstChildOfClass("BodyVelocity"):remove()
end
end
end)
Mouse.KeyUp:Connect(function(key)
if key == "w" then
wToggle = false
end
end)
【问题讨论】:
-
如果你想打一次
G然后使用W飞行,我会将G设置为仅用于打开或关闭飞行的布尔切换,并将实际飞行代码放入W
标签: roblox