【问题标题】:The location finder is not working and instead is showing something unusual. Any help? Roblox Studio位置查找器不工作,而是显示一些不寻常的东西。有什么帮助吗?罗布洛克斯工作室
【发布时间】:2023-03-03 23:05:01
【问题描述】:

我正在尝试制造一种符合我所有标准的枪,并且到目前为止进展顺利。我编写了一个代码,每次玩家点击鼠标时,它都会记录枪管的位置,这是一个额外的秘密部分,它只是产生子弹的地方。不幸的是,我必须使用本地脚本,因为服务器脚本会在你正在处理它的隐藏枪上产生子弹。因此,我想使用远程事件将信息发送到服务器脚本以在那里生成子弹。但由于某种原因,它说“VoltyDeElectroDragon 328.80020141602 3.400004863739”而不是“328.80020141602 3.400004863739 -144.67500305176”,我不知道出了什么问题。我的枪的不同版本也出现了同样的问题。这是本地脚本代码:

local mouse = player:GetMouse()
local barrel = script.Parent:WaitForChild("Barrel", 0.00001)
local barrelx = barrel.Position.X
local barrely = barrel.Position.Y
local barrelz = barrel.Position.Z

script.Parent.Equipped:Connect(function()
    script.Parent.Activated:Connect(function()
        local HitX = mouse.Hit.X
        local HitY = mouse.Hit.Y
        local HitZ = mouse.Hit.Z
        print(barrelx, barrely, barrelz)
        script.Parent.Fire:FireServer(barrelx, barrely, barrelz)
    end)
end)

这里是服务器脚本代码:

local bullet = game.ReplicatedStorage.Bullet
local gunposX = script.Parent.Barrel.Position.X
local gunposY = script.Parent.Barrel.Position.Y
local gunposZ = script.Parent.Barrel.Position.Z

local function Fire(barrelx, barrely, barrelz)
    print(barrelx, barrely, barrelz)
    part.Position = Vector3.new(HitX, HitY, HitZ)
    local bulletcopy = bullet:Clone()
    bulletcopy.Parent = game.Workspace
    bulletcopy.Position = Vector3.new(gunposX, gunposY, gunposZ)
    local Bulletshoot = Instance.new("BodyForce", bulletcopy)
    Bulletshoot.Force = Vector3.new(0, 0, 100)
end

script.Parent.Fire.OnServerEvent:Connect(Fire)

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    RemoteEventOnServerEvent 上的第一个参数是称为FireServer()player

    您需要更新函数签名以解决此问题:

    local function Fire(player, barrelx, barrely, barrelz)
    

    【讨论】:

      猜你喜欢
      • 2021-02-02
      • 2021-12-03
      • 2022-01-23
      • 2022-01-05
      • 2021-07-27
      • 2018-03-08
      • 2020-08-24
      • 2017-07-24
      • 1970-01-01
      相关资源
      最近更新 更多