Lua 未克隆该块,且未显示任何错误消息。(Roblox Studio)
我正在制作一个放置系统(到目前为止是基本的),但它没有放置任何东西。代码一直工作到“while whenclicked=true”部分,下面是代码:Lua 未克隆该块,且未显示任何错误消息。(Roblox Studio),lua,roblox,Lua,Roblox,我正在制作一个放置系统(到目前为止是基本的),但它没有放置任何东西。代码一直工作到“while whenclicked=true”部分,下面是代码: print('works') while true do print('works2') local ImportedValueX = game.ReplicatedStorage.ActPosX local ImportedValueY = game.ReplicatedStorage.ActPosY local
print('works')
while true do
print('works2')
local ImportedValueX = game.ReplicatedStorage.ActPosX
local ImportedValueY = game.ReplicatedStorage.ActPosY
local ImportedValueZ = game.ReplicatedStorage.ActPosZ
local Block = game.ReplicatedStorage.Experimental
local WhenClicked = game.ReplicatedStorage.WhenClicked.Value
print('works3')
while WhenClicked == true do
print('wore')
PlacedBlock = Block:Clone()
PlacedBlock.Parent = workspace
PlacedBlock.Position.X = ImportedValueX
PlacedBlock.Position.Y = ImportedValueY
PlacedBlock.Position.Z = ImportedValueZ
WhenClicked = false
wait(1)
end
wait(0.1)
end
变量工作正常,whinclick部分也工作正常,我认为while-whinclick部分已损坏。我发现了一个问题:
PlacedBlock.Position.X = ImportedValueX
PlacedBlock.Position.Y = ImportedValueY
PlacedBlock.Position.Z = ImportedValueZ
X、Y、Z是只读属性。您需要通过创建新的Vector3对象并将其指定给Position属性来填充它们,如下所示:
PlacedBlock.Position = Vector3.new(ImportedValueX, ImportedValueY, ImportedValueZ)
local event = Instance.new("RemoteEvent", game.ReplicatedStorage)
event.Name = "MyRemoteEvent"
local Block = game.ReplicatedStorage.Experimental
event.OnServerEvent:Connect(function(plr, position, whenClicked)
if whenClicked then
print('wore')
local placedBlock = Block:Clone()
placedBlock.Parent = workspace
placedBlock.Position = position
end
end)
-- wait until the server has created the remote event
local event = game.ReplicatedStorage:WaitForChild("MyRemoteEvent")
-- do whatever you need to do, then call trigger the event:
event:FireServer(Vector3.new(5,5,5), true)
更新: 我假设您正试图使用复制存储将鼠标单击状态(单击时)从客户端发送到服务器。然后服务器检查状态以及循环中的x/y/z位置。这不起作用,因为ReplicatedStorage不会将您的值复制到服务器。否则,这可能是一个漏洞。 因此,为了从客户端向服务器发送信号,您应该使用RemoteEvent或RemoteFunction(请参阅参考手册)。在您的情况下,服务器脚本可能如下所示:
PlacedBlock.Position = Vector3.new(ImportedValueX, ImportedValueY, ImportedValueZ)
local event = Instance.new("RemoteEvent", game.ReplicatedStorage)
event.Name = "MyRemoteEvent"
local Block = game.ReplicatedStorage.Experimental
event.OnServerEvent:Connect(function(plr, position, whenClicked)
if whenClicked then
print('wore')
local placedBlock = Block:Clone()
placedBlock.Parent = workspace
placedBlock.Position = position
end
end)
-- wait until the server has created the remote event
local event = game.ReplicatedStorage:WaitForChild("MyRemoteEvent")
-- do whatever you need to do, then call trigger the event:
event:FireServer(Vector3.new(5,5,5), true)
因此,这将在ReplicatedStorage中创建一个远程事件,然后侦听它。当从客户端调用它时,它将执行您想要执行的操作(克隆零件并定位它)
在客户端脚本中,您将触发如下事件:
PlacedBlock.Position = Vector3.new(ImportedValueX, ImportedValueY, ImportedValueZ)
local event = Instance.new("RemoteEvent", game.ReplicatedStorage)
event.Name = "MyRemoteEvent"
local Block = game.ReplicatedStorage.Experimental
event.OnServerEvent:Connect(function(plr, position, whenClicked)
if whenClicked then
print('wore')
local placedBlock = Block:Clone()
placedBlock.Parent = workspace
placedBlock.Position = position
end
end)
-- wait until the server has created the remote event
local event = game.ReplicatedStorage:WaitForChild("MyRemoteEvent")
-- do whatever you need to do, then call trigger the event:
event:FireServer(Vector3.new(5,5,5), true)
不幸的是,问题来自while循环(我认为)不是位置,而是感谢您帮助我解决了未来的问题!然后检查更新的答案。我认为你的问题在于复制本身。