Is this line running on a server-sided script or a local script?
Im sorry for being confusing⌠I should not go fast. That line you are showing its a different issue I pointed out. Its not related with the issue you are currently experiencing. I said, that could be fixed later.
Could you show another error that is actually related with the script you are showing, cause this error is not related:
a local in here:
ok idk if ive fixed it but on here i changed player to players:
players.PlayerRemoving:Connect(function(player)
Sorry, you guys are confused. This fix the error of not having a proper Player Instance, I already sent it:
egg.ProximityPrompt.Triggered:Connect(function(Player)
local eggData = require(egg.Data)
local price = eggData.eggPrice
local currency = eggData.eggCurrency
if Player.leaderstats.Gems.Value >= price then
if not playerHatchDebounce[Player] then
playerHatchDebounce[Player] = true
local chosenPet = chooseRandomPet(eggData.eggPets)
Player.leaderstats[currency].Value -= price
remotes.HatchEgg:FireClient(Player, egg.Name, chosenPet)
local val = Instance.new("StringValue")
val.Name = tostring(chosenPet.petName)
val.Parent = Player.Pets
task.wait(6)
playerHatchDebounce[Player] = false
end
end
end)
BUT, that is not the problem after fixing it⌠The problem is that playerHatchDebounce table HAS NOT keys per player, and OP is trying to get a key based on player as stated in this line:
if not playerHatchDebounce[Player] then
That key doesnt exist, cause it was never created
if it is a fix, all i need to sort out is the infinite yield on the other script
oh cmon⌠that warn is not even related to the issue you are experiencing⌠are you reading what Im saying?
Can you check if the path Players.origamimaster7225.PlayerGui.EggViewerSystem"
Isnât nil and StarterGui.EggViewerSystem"
Isnât nil
yeah i have no key for it⌠im just wondering how to make one
local replicatedStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players")
local remotes = replicatedStorage.Remotes
local eggs = workspace.Mainfolder_workspace.Eggs
local playerHatchDebounce = {}
local function chooseRandomPet(petTable)
local chosenPet = nil
local randomNumber = math.random(1, 100)
local weight = 0
for i, v in pairs(petTable) do
weight += v.chance
if weight >= randomNumber then
chosenPet = v
break
end
end
return chosenPet
end
for _, egg in pairs(eggs:GetChildren()) do
egg.ProximityPrompt.Triggered:Connect(function(player)
local eggData = require(egg.Data)
local price = eggData.eggPrice
local currency = eggData.eggCurrency
if Player.leaderstats.Gems.Value >= price then
if playerHatchDebounce[player] then
else
playerHatchDebounce[player] = true
local chosenPet = chooseRandomPet(eggData.eggPets)
Player.leaderstats[currency].Value -= price
remotes.HatchEgg:FireClient(player, egg.Name, chosenPet)
local val = Instance.new("StringValue")
val.Name = tostring(chosenPet.petName)
val.Parent = player.Pets
task.wait(6)
playerHatchDebounce[player] = false
end
end
end)
end
player.PlayerRemoving:Connect(function(player)
if playerHatchDebounce[player] then
playerHatchDebounce[player] = nil
end
end)
i changed the code a bit
I think it will fix it
I am trying to solve the latest error they were getting which is the warning
No it wont due to this line:
playerHatchDebounce[player]
Please someone can understand what Im saying? OP is trying to find a key that doesnt exist in that table⌠a Table that is based on Playerâs keys, and that Table is literally emptyâŚ
How script would find that Key if it doesnt even exist? it never got created by the scriptâŚ
i created a remote thats what that is
It can because if you put in the script
playerHatchDebounce[player] = true
then it will create a key
and if u say
playerHatchDebounce[player] = false
then it will create or change the key
here is the script for the yield:
local runService = game:GetService("RunService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local tweenService = game:GetService("TweenService")
local eggs = workspace:WaitForChild("Mainfolder_workspace"):WaitForChild("Eggs")
local remotes = replicatedStorage:WaitForChild("Remotes")
local pets = replicatedStorage:WaitForChild("Pets")
local player = players.LocalPlayer
local eggSystemSS = player:WaitForChild("PlayerGui"):WaitForChild("EggViewerSystem")
local eggViewport = eggSystemSS:WaitForChild("EggViewer")
local function hatchEgg(eggName, chosenPet)
for _, v in pairs(player.PlayerGui:GetChildren()) do
if v: IsA("ScreenGui") and v ~= eggSystemSS then
v.Enabled = false
end
end
eggSystemSS.Enabled = true
for _, v in pairs(eggViewport:GetChildren()) do
if v: IsA("Camera") or v:IsA("BasePart") or v:IsA("Model") then
v:Destroy()
end
end
eggViewport.Size = UDim2.fromScale(0, 0)
local eggMesh = eggs:FindFindFirstChild(eggName):Clone()
eggMesh.Parent = eggViewport
eggMesh.CFrame = CFrame.new(0, 0, 0)
local camera = Instance.new("Camera")
camera.Parent = eggViewport
camera.CFrame = CFrame.new(0, 0, 4)
eggViewport.CurrentCamera = camera
tweenService:Create(eggViewport, TweenInfo.new(0.7), {Size = UDim2.new(0.267, 0,0.437, 0)}):Play()
task.wait(0.7)
for i = 1, 4 do
tweenService:Create(eggViewport, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = 20}):Play()
task.wait(0.3)
tweenService:Create(eggViewport, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = -20}):Play()
task.wait(0.3)
end
tweenService:Create(eggViewport, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = 0}):Play()
task.wait(0.3)
tweenService:Create(eggViewport, TweenInfo.new(0.7), {Size = UDim2.fromScale(0, 0)}):Play()
task.wait(0.3)
for _, v in pairs(eggViewport:GetChildren()) do
if v: IsA("Camera") or v:IsA("BasePart") or v:IsA("Model") then
v:Destroy()
end
end
local petModel = pets:FindFirstChild(chosenPet.petName):Clone()
petModel:Pivotto(CFrame.new(0, 0, 0))
petModel.Parent = eggViewport
local cameraPet = Instance.new("Camera")
cameraPet.Parent = eggViewport
cameraPet.CFrame = CFrame.new(0, 0, -3.3) * CFrame.Angles(0, math.rad(180), 0)
eggViewport.currentcamera = cameraPet
tweenService:Create(eggViewport, TweenInfo.new(0.7), {Size = UDim2.new(0.267, 0,0.437, 0)}):Play()
eggViewport.NameLabel.Text = chosenPet.petname
eggViewport.NameLabel.Visible = true
eggViewport.RarityLabel.Text = chosenPet.Rarity
eggViewport.RarityLabel.Visible = true
task.wait(1.5)
tweenService:Create(eggViewport, TweenInfo.new(0.3), {Size = UDim2.fromScale(0, 0)}):Play()
task.wait(0.3)
eggViewport.NameLabel.Visible = false
eggViewport.RarityLabel.Visible = false
for _, v in pairs(player:WaitForChild("PlayerGui"):GetChildren()) do
if v: IsA("ScreenGui") and v ~= eggSystemSS then
v.Enabled = true
end
end
end
remotes:WaitForChild("HatchEgg").OnClientEvent:Connect(hatchEgg)
Can you add this right after line 13 print(âWorks!â)
, and filter the output console with Works!
The yield error might be caused because the WaitForChild function isnât returning fast enough.
A table index (key) can be any datatype (Instance, function, boolean, number, string, etc.). In this case, I assume that you want a player-only debounce system that will limit the player from hatching another egg for some time since there is no local player in a server-side script, which runs on the Roblox server and cannot know which player you meant. Therefore, you need to specify the player. in playerHatchDebounce[player]
It would debounce the server, so consider changing every playerHatchDebounce[player]
to playerHatchDebounce[Player]
ok so do you know how i would do that?
didnt work: