Iam making a simulator game with a friend but I was scripting the pets but I run into a problem but can’t fix it
I can’t buy the pet and the output says ‘attemt to index nill with ‘name’’
I tried pretty much everything and im not really a scripter so-
I hope someone can help me
the script:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new('Folder', player)
leaderstats.Name = 'leaderstats'
local Pets = Instance.new('Folder', player)
Pets.Name = 'Pets'
local coins = Instance.new('IntValue', leaderstats)
coins.Name = 'Coins'
coins.Value = 15
player.CharacterAdded:Connect(function(char)
local attachement = Instance.new('Attachment', char.HumanoidRootPart)
attachement.Name = 'CharacterAt'
end)
end)
game.ReplicatedStorage.Remotes.Add.OnServerEvent:Connect(function(player,ammount)
local currency = 'Coins'
player.leaderstats[currency].Value = player.leaderstats[currency].Value
end)
game.ReplicatedStorage.RemoteFunctions.EquipPet.OnServerInvoke = function(player, pet)
local currency = 'Coins'
local MainPet = game.ServerStorage.Pets:FindFirstChild(pet)
if not player.Pets:FindFirstChild(MainPet.Name) then
if player.leaderstats[currency].Value >= MainPet.Price.Value then
player.leaderstats[currency].Value = player.leaderstats[currency].Value - MainPet.Price.Value
local clonedPet = MainPet:Clone()
clonedPet.Parent = player.Character
clonedPet:SetPrimaryPartCFrame(player.Character.Head.CFrame)
local atPet = Instance.new('Attachment', clonedPet.PrimaryPart)
local at1 = Instance.new('Attachment', player)
local ap = Instance.new('AlignPosition')
ap.Parent = clonedPet
ap.RigidityEnabled = true
ap.Attachment0 = atPet
ap.Attachment1 = player.Character.HumanoidRootPart.CharacterAt
return 'Bought'
else
return 'Not enough coins'
end
else
return 'Equip'
end
end