如何修复"ServerScriptService.Earthquake:11: attempt to index nil with 'OnServerEvent'"



我已经通过代码多次,不能找到任何可能导致这种情况。我只是瞎了眼,如果是的话,你能给我指个方向吗?

下面是我的代码:

local rp = game:GetService("UserInputService")
local remote = rp:WaitForChild("Earthquake")
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local Meshes = script:WaitForChild("Meshes")
local damage = 15
remote.OnServerEvent:Connect(function(player)
local char = player.Character
local humrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local folder = Instance.new("Folder", workspace)
folder.Name = player.Name.."'s Earthquake"
local anim = hum:LoadAnimation(script:WaitForChild("anim"))
anim:Play()
wait(0.9)
for count = 1, 15 do 
local rock = Meshes:WaitForChild("rock"):Clone()
rock.Parent = folder
rock.Size = Vector3.new(math.random(4,9),0.05,math.random(4,9))
rock.Cframe = humrp.CFrame * CFrame.new(0,3,-count*6)
rock.Orientation = rock.Orientation + Vector3.new(math.random(-20,20),math.random(-20,20),math.random(-20,20))

local tweenRand = math.random(7,15)


local tween =  TweenService:Create(rock, TweenInfo.new(0.2),{Size = rock.Size + Vector3.new(0, tweenRand,0), Position = rock.Position + Vector3.new(0,(tweenRand/2)-3,0)})
tween:Play()
wait(0.1)
end
end)

错误告诉您,在第11行,remote为nil,这意味着第2行未能在UserInputService中找到RemoteEvent。根据对这个问题的评论,RemoteEvent不在UserInputService中,它实际上在ReplicatedStorage中。

要解决这个问题,只需更新代码,使其指向ReplicatedStorage。

local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("Earthquake")

相关内容

  • 没有找到相关文章

最新更新