【问题标题】:The cars won't delete or delete others cars what do I do (Roblox)这些汽车不会删除或删除其他汽车我该怎么办(Roblox)
【发布时间】:2019-07-14 13:16:01
【问题描述】:

我如何让这段代码在玩家点击它时只删除玩家的汽车,这样当其他人生成他们的汽车时它不会删除其他汽车?

local model = game.Workspace.Car --or whatever the path to the model of your car is
local button = script.Parent --or whatever the path to your button is
local destination = Vector3.new(x, y, z) --the 3D coordinates of where you'd like the car to spawn

local function spawnCar()
     model:MoveTo(destination) --use this if you want to move the car that's in the dealership
     model:Clone():MoveTo(destination) --use this if you want to make a copy of the car and move that
end

button.MouseButton1Down:connect(spawnCar) --notice it's "spawnCar", NOT "spawnCar()"

【问题讨论】:

    标签: roblox


    【解决方案1】:

    我知道你是 Stack Overflow 的新手!

    我假设您问的是如何重写代码,以便只有车主可以删除汽车。

    我只想指出你犯的一个错误;在 spawnCar 函数中,您已经告诉汽车移动位置,然后克隆自身并再次移动。这将导致两辆车同时出现,因此我建议您选择其中一辆。

    要回答您的问题,我们可以先将 ClickDetector 添加到汽车的零件中。将此部分命名为“DeleteButton”。然后,创建一个零件,将其放在汽车的某个位置,将 ClickDetector(右键单击零件 -> 插入 -> ClickDetector)插入零件并将零件放入汽车模型中。我还希望您在模型中插入一个 StringValue(右键单击 -> 插入 -> StringValue)。

    接下来,打开你的脚本,我们就开始了。

    下面是一些经过编辑的代码,可帮助您为车主添加删除功能。

    local model = game.Workspace.Car --or whatever the path to the model of your car is
    local playerValue = game.Workspace.Car.StringValue
    local deleteButton = game.Workspace.Car.DeleteButton
    local button = script.Parent --or whatever the path to your button is
    local destination = Vector3.new(x, y, z) --the 3D coordinates of where you'd like the   car to spawn
    
    local function spawnCar(Clicker)
         model:MoveTo(destination) --use this if you want to move the car that's in the  dealership
         model:Clone():MoveTo(destination) --use this if you want to make a copy of the car and move that
         playerValue.Value = Clicker.Name -- sets the person who clicked's name to the value.
    end
    
    local function deleteCar(Clicker)
         if playerValue.Value == Click.Name then -- if the players name is the same as the owner's name
                model:Destroy() -- destroy the car if it is
         end
    end
    
    
    button.MouseClick:Connect(spawnCar) --notice it's "spawnCar", NOT "spawnCar()"
    deleteButton.MouseClick:Connect(deleteCar) -- notice it's "deleteCar", NOT "deleteCar()"
    

    总而言之,这就是我编辑的内容:我添加了两个新变量,用于播放器值的路径和一个新按钮部件;我在代码中添加了一行,将玩家值设置为玩家的名字;我创建了一个函数来检测玩家的名字是否与值相同,它将删除汽车。最后我加了一句,说当Detector被点击时,它会做delete car的功能。

    您需要注意的更正:

    -> MouseButton1Click/Down 用于 GUI,使用 MouseClick!

    -> 选择一个或另一个(你移动了一辆车两次!)

    -> 你仍然需要设置你希望汽车在目的地线产生的位置,例如local destination = Vector3.new(1, 1, 1) 等。

    如果这篇文章对您有帮助,并且回答了您的问题,请务必点赞,别忘了打勾并将其标记为正确!

    罗斯,我很高兴在 cmets 中提供帮助。

    【讨论】:

    • 我觉得我使用的生成器类型不是现在我找到了这段代码,但它再次出现了同样的问题,它删除了其他人的汽车,只有一个人可以得到汽车。但我仍在检查 spawnersystem = script.Parent model = system.Station -- backup = model:Clone() regen = system.Regen function checkRegen() if regen.Value == 1 then model:remove() wait(1 ) model = backup:Clone() model.Parent = system model:MakeJoints() end end regen.Changed:connect(checkRegen)
    • @Morgun1127 好的,找到您的问题。当您“克隆”汽车时,您将其保留为相同的名称。由于每个人都有相同的汽车名称,在同一个位置,代码删除了 Workspace 中名为“汽车”的所有模型,即每个人的。您可以通过在此 pastebin 中将整个 spawnCar 和 deleteCar 函数替换为以下内容来解决此问题; pastebin.com/i76nZESW
    猜你喜欢
    • 2013-11-09
    • 2020-03-30
    • 1970-01-01
    • 2018-10-13
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    • 2022-06-29
    • 1970-01-01
    相关资源
    最近更新 更多