参数1缺失或roblox studio上的nil错误



祝你过得愉快。我只是想说我已经看了Alvinblox的蛋孵化系统教程,我现在正在看第二部分。有一个新的错误叫做"参数1丢失或nil"它位于petFollowPlayer脚本(local pet = game.ReplicatedStorage.HatchablePets:FindFirstChild(petName))的第60行,下面是代码

petFollowPlayer

local function equipPet(player, pet, petName)
print(player)
local character = player.Character
if pet ~= nil and character ~= nil then
if character:FindFirstChild(player.Name.."s' pet") then
character(player.Name.."s' pet"):Destroy()
end
if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
end
pet.Name = player.Name.."'s pet"
pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
local modelSize = pet.PrimaryPart.Size
local attachmentCharacter = Instance.new("Attachment")
attachmentCharacter.Visible = false
attachmentCharacter.Parent = character.HumanoidRootPart
attachmentCharacter.Position = Vector3.new(-1,0,1) + modelSize
attachmentCharacter.Name = "attachmentCharacter"
local attachmentPet = Instance.new("Attachment")
attachmentPet.Parent = pet.PrimaryPart
local alignPosition = Instance.new("AlignPosition")
alignPosition.MaxForce = 25000
alignPosition.Attachment0 = attachmentPet
alignPosition.Attachment1 = attachmentCharacter
alignPosition.Responsiveness = 25
alignPosition.Parent = pet
local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.MaxTorque = 25000
alignOrientation.Attachment0= attachmentPet
alignOrientation.Attachment1= attachmentCharacter
alignOrientation.Responsiveness = 25
alignOrientation.Parent = pet

pet.Parent = character
end
end
game.Players.PlayerAdded:Connect(function(player)
local equipedPet = Instance.new("StringValue")
equipedPet.Name = "EquipedPet"
equipedPet.Parent = player
equipedPet.Value = ""
player.CharacterAdded:Connect(function(char)
if game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value) then
local clone =game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value):Clone()
equipPet(player,clone)
end
end)
equipedPet.Changed:Connect(function ()
if equipedPet.Value ~= nil then
if game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value) then
equipPet(player, game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value):Clone())

end
end
end)
end)
game.ReplicatedStorage.equipPet.OnServerEvent:Connect(function(player,petName)
local pet = game.ReplicatedStorage.HatchablePets:FindFirstChild(petName)
if pet and player.PetInventory:FindFirstChild(petName) then
player.EquipedPet.Value = petName
end
end)
game.ReplicatedStorage.unequipPet.OnServerEvent:Connect(function(player)
player.EquippedPet.Value = ""
if player.Character:FindFirstChild(player.Name.."'s name") then
player.Character[player.Name.."'s pet"]:Destroy()
end
if player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
end
end)

buyBasicEgg

local cost = 50
local petMoudle = require(game.ServerScriptService.BasicEggModule)
local prompt = workspace["Egg Holder"].Part.ProximityPrompt

prompt.Triggered:Connect(function (player)
if player.leaderstats.Cash.Value >= cost then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost
local pet = petMoudle.chooseRandomPet()
local petval = Instance.new("StringValue")
petval.Name = pet.Name
petval.Parent = player.PetInventory
print(pet.Name.." selected")
game.ReplicatedStorage.HatchEgg:FireClient(player, pet)
end
end)

basicEggAnimation

local camera = workspace.Camera
local studio = workspace.Studio
local template = script.Parent.Pets.ScrollingFrame.Template
local scrollingFrame = script.Parent.Pets.ScrollingFrame
local buttonConnection = {}
local function setTemplateEquipped()
for i,v in pairs(scrollingFrame:GetChildren()) do
if v:FindFirstChild("Equipped") then
v.Equipped.Text = "UNEQUIPPED"
v.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
end
end
template.Equiped.Text = "Equipped"
template.Equiped.TextColor3 = Color3.fromRGB(0,255,0)
end
local function addToFrame(pet)
local newTemplate = template:Clone()
newTemplate.Name = pet.Name
newTemplate.petName.Text = pet.Name
newTemplate.Parent = scrollingFrame
newTemplate.Visible = true
local camera = Instance.new("Camera")
local newPet = pet:Clone()
newPet.Parent = newTemplate.ViewportFrame
camera.CFrame = CFrame.new(newPet.PrimaryPart.Position + (newPet.PrimaryPart.CFrame.LookVector * 3), newPet.PrimaryPart.Position)
camera.Parent = newTemplate.ViewportFrame
newTemplate.ViewportFrame.CurrentCamera = camera
buttonConnection[#buttonConnection+1] = newTemplate.MouseButton1Click:Connect(function()
if newTemplate.Equiped.Text == "EQUIPPED" then
game.ReplicatedStorage.unequipPet:FireServer(pet.Name)
newTemplate.Equiped.Text = "UNEQUIPPED"
newTemplate.Equiped.TextColor3 = Color3.fromRGB(255,0,0)
else
game.ReplicatedStorage.equipPet:FireServer()
setTemplateEquipped(newTemplate)
end
end)
end
game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function (pet)
addToFrame(pet)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = studio.CameraPart.CFrame
wait(1.5)
for i = 1,50,1 do
studio["Egg Mesh"].Size = studio["Egg Mesh"].Size + Vector3.new(0.1,0.1,0.1)
wait(0.01)
end
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 10
explosion.BlastPressure = 0
explosion.Position = studio["Egg Mesh"].Position
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.DestroyJointRadiusPercent = 0
explosion.Parent = studio["Egg Mesh"]
studio["Egg Mesh"].Transparency = 1
local petClone = pet:Clone()
for i,v in pairs(petClone:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = true
end
end 
petClone:SetPrimaryPartCFrame(CFrame.new(studio["Egg Mesh"].Position, studio.CameraPart.Position))
petClone.Parent = studio
petClone.PrimaryPart.Position = Vector3.new(-14.382, -8.112, -605.565)
petClone.PrimaryPart.Anchored = true
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.Out,
0,
false,
0
)
local TweenService = game:GetService("TweenService")
local targetVector = petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0)
local lookVector = petClone.PrimaryPart.Position
local targetCframe = CFrame.new(targetVector, lookVector)
local propsToTween = { CFrame = targetCframe }
local tween  = TweenService:Create(camera, tweenInfo, propsToTween)
tween:Play()
wait(5)
for i,v in pairs(petClone:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end 
camera.CameraType = Enum.CameraType.Custom
studio["Egg Mesh"].Transparency = 0
studio["Egg Mesh"].Size = Vector3.new(4.732, 6, 4.732)
petClone:Destroy()
end)

如果你能帮上忙,我将不胜感激:)

local pet = game.ReplicatedStorage.HatchablePets:FindFirstChild(petName)

错误告诉您,由于某种原因,petName没有定义。看看变量是如何定义的,我们需要检查game.ReplicatedStorage.equipPet是如何被调用的。看看addToFrame本地函数,你这样调用它:game.ReplicatedStorage.equipPet:FireServer()。你的问题是你根本没有提供宠物的名字。因此,只需对unequipPet事件做同样的事情。

buttonConnection[#buttonConnection+1] = newTemplate.MouseButton1Click:Connect(function()
if newTemplate.Equiped.Text == "EQUIPPED" then
game.ReplicatedStorage.unequipPet:FireServer(pet.Name)
newTemplate.Equiped.Text = "UNEQUIPPED"
newTemplate.Equiped.TextColor3 = Color3.fromRGB(255,0,0)
else
game.ReplicatedStorage.equipPet:FireServer(pet.Name)
setTemplateEquipped(newTemplate)
end
end)

相关内容

  • 没有找到相关文章