该块未被克隆且未显示任何错误消息。(Roblox Studio)
The block is not being cloned and no error message is showing.(Roblox Studio)
我正在制作一个放置系统(到目前为止它是基本的)但它没有放置任何东西。代码一直运行到 'while whenclicked = true' 部分,这里是代码:
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
变量工作正常,whenclick 部分也工作,我认为 while whenclicked 部分坏了。
我在这里看到一个问题:
PlacedBlock.Position.X = ImportedValueX
PlacedBlock.Position.Y = ImportedValueY
PlacedBlock.Position.Z = ImportedValueZ
X、Y、Z 为只读属性。您需要通过创建一个新的 Vector3 对象并将其分配给位置 属性 来填充它们,如下所示:
PlacedBlock.Position = Vector3.new(ImportedValueX, ImportedValueY, ImportedValueZ)
已更新:
我假设您正在尝试使用复制存储将鼠标单击状态 (whenClicked) 从客户端发送到服务器。服务器然后检查状态以及循环中的 x/y/z 位置。这不起作用,因为 ReplicatedStorage 不会将您的值复制到服务器。否则这可能是漏洞利用的机会。
因此,为了从您的客户端向您的服务器发出信号,您应该使用 RemoteEvent 或 RemoteFunction(在参考手册中查找它们)。在您的情况下,您的服务器脚本可能如下所示:
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)
所以这会在 ReplicatedStorage 中创建一个远程事件,然后监听它。当从客户端调用它时,它将执行您想要执行的操作(克隆零件并定位)。
在您的客户端脚本中,您将像这样触发事件:
-- 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 whenclicked = true' 部分,这里是代码:
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
变量工作正常,whenclick 部分也工作,我认为 while whenclicked 部分坏了。
我在这里看到一个问题:
PlacedBlock.Position.X = ImportedValueX
PlacedBlock.Position.Y = ImportedValueY
PlacedBlock.Position.Z = ImportedValueZ
X、Y、Z 为只读属性。您需要通过创建一个新的 Vector3 对象并将其分配给位置 属性 来填充它们,如下所示:
PlacedBlock.Position = Vector3.new(ImportedValueX, ImportedValueY, ImportedValueZ)
已更新:
我假设您正在尝试使用复制存储将鼠标单击状态 (whenClicked) 从客户端发送到服务器。服务器然后检查状态以及循环中的 x/y/z 位置。这不起作用,因为 ReplicatedStorage 不会将您的值复制到服务器。否则这可能是漏洞利用的机会。 因此,为了从您的客户端向您的服务器发出信号,您应该使用 RemoteEvent 或 RemoteFunction(在参考手册中查找它们)。在您的情况下,您的服务器脚本可能如下所示:
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)
所以这会在 ReplicatedStorage 中创建一个远程事件,然后监听它。当从客户端调用它时,它将执行您想要执行的操作(克隆零件并定位)。
在您的客户端脚本中,您将像这样触发事件:
-- 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)