是的,所以我只是在制作一款体育游戏,我基本上需要一个接球/持球系统,它第一次在双方都有效,但在我抛出之后,它只是出现故障,球在客户端一直从我身边跑开,但是在服务器端,它说我已经掌握了球,我将在代码中添加一些注释以便更好地理解。
-- This script is made in StarterCharacterScripts --
while true do -- a loop looping forever to check if the character is touching anything
for i,v in ipairs(script.Parent:GetChildren()) do -- Looping through the whole body check all the body parts
if v:IsA("Part") or v:IsA("MeshPart") then -- Checking if it is a body part (just to prevent it checking he humanoid so we won't get an error
v.Touched:Connect(function(hit) -- see if the body part is touching anything
if hit.Name == "Ball" then -- Checking if it is a ball
print("Ball")
hit.Parent = script.Parent -- putting the ball inside of the body
hit.Joint.Part0 = script.Parent.RightHand -- positioning it on the right place
print("Holding")
end
end)
wait()
end
end
wait()
end
这是我现在使用的代码,我之前还有一个。
local BALL = require(game.ServerScriptService.ModuleScript) -- requiring the base module
script.Parent.Touched:Connect(function(hit) -- Checking if the ball is touched by anything
if hit.Parent:FindFirstChild("Humanoid") then -- see if it is a player
BALL.Pickup(hit, script.Parent) -- Using the function from the module
end
end)
这是模块
local BALL = {} -- the table
BALL.Pickup = function(hit, ball) -- The function
ball.Parent = hit.Parent -- setting its parent
ball.Joint.Part0 = hit.Parent:WaitForChild("RightHand") -- positioning again
print(ball.Joint.Part0) -- just for debugging
end
return BALL
希望大家能帮我解决这个问题 顺便说一句,球并没有在 roblox 玩家身上跑掉,但我就是抓不到它
这是一个非常复杂的问题。我的第一个猜测是服务器和客户端不是确定性的。因此,您正在检查 HIT 以确定球是否与玩家(人形)接触 - 但确定这一点的计算在客户端和服务器上的结果不同。这个术语称为确定性物理学,它是每个制作实时在线游戏的游戏开发人员的福音。 (可能不是,可能只有我讨厌这个。)