You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
A working pet system
What is the issue?
The issue is it comes up with an error showing “attempt to index nil with ‘Pets’”.
What solutions have you tried so far?
Finding a solution
local DB = false
local XPgain = 25
local Delay = 0.1
script.GiveXp.OnServerEvent:Connect(function()
local Player = game.Players.LocalPlayer
for i,v in pairs(Player.Pets:GetChildren()) do
if v.Equipped.Value == true then
v.TotalXP.Value = v.TotalXP.Value + XPgain
end
end
for i,v in pairs(workspace.PlayerPets:FindFirstChild(Player.Name):GetChildren()) do
spawn(function()
local Clone = game.ReplicatedStorage.Pets.AddXPdisplay:Clone()
Clone.Parent = v.PrimaryPart
for i = 1,25 do
Clone.StudsOffset = Clone.StudsOffset + Vector3.new(0, .04, 0)
Clone.TextLabel.TextTransparency = Clone.TextLabel.TextTransparency + .04
wait(.02)
end
Clone:Destroy()
end)
end
DB = true
wait(Delay)
DB = false
end)
Which line is the error showing as on, can you show me your output and the area where the link on the output leads you? I cannot tell which “Pets” part it is, thank you.
I will also explain what Valentin did to help you learn;
When you send an event from the client to the server, the client automatically sends which player it is too. So if you call for a variable as the first in the function, you will receive the player instance. (Order matters!)
When ever I click it gives xp but it starts of slow and the goes really fast even when I click slow it is like add more xp to the pet! https://gyazo.com/ead38686c45a73149a6195a48f0e012a
You might not be able to tell from the little clip.
function getLevel(totalXP)
local Increment = 0
local RequiredXP = 100
for i = 0, RS.Pets.Settings.MaxPetLevel.Value do
RequiredXP = 100 + (25*i)
if totalXP >= (100*i) + Increment then
if i ~= RS.Pets.Settings.MaxPetLevel.Value then
if totalXP < ((100*i) + Increment) + RequiredXP then
return i
end
else
return i
end
end
Increment = Increment+(i*25)
end
end
function getMaxXP(MaxLevel)
local MaxXP = 0
for i = 0,MaxLevel do
if i == MaxLevel then
return MaxXP + (100 * (i+1))
else
MaxXP = MaxXP + (i*25)
end
end
end
GiveXp is a remote event correct? In the parameters, just do ‘player’ and use it as the player instead of using ‘game.Players.LocalPlayer’ because as it suggests, its local, it does not work in server scripts..