remotes.HatchEgg:FireClient(player, egg.Name, chosenPet)
show the rest of the script, your “player” variable is not a real player instance
k
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 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)
end
player.PlayerRemoving:Connect(function(player)
if playerHatchDebounce[player] then
playerHatchDebounce[player] = nil
end
end)
You are using FireClient, which means this is a Server Script, but you are getting the “player” variable like this:
local player = game:GetService("Players")
Which firstly, doesnt even reference a Player, its only the PlayersService.
k so how would i get thevariable player for this?
Just change all player to Player, cause Player is a variable that came from the Proximity event, and it has the real Player instance:
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)
ah yes ty but now its erroring the PlayerRemoving:
code:
Player.PlayerRemoving:Connect(function(player)
if playerHatchDebounce[player] then
playerHatchDebounce[player] = nil
end
end)
You dont need to change that player to Player.
player variable holds the PlayerService. And PlayerService is the one that has the PlayerRemoving event. Change that back to only “player”… which is the variable that holds the PlayerService, you only needed to change the code I sent
still says the error for some reason
And by kinda reading the “future” you will still have some issues cause you didnt show how you built the:
local playerHatchDebounce = {}
table
This scripts looks like a somekind of migrating it from local script to serverSide
Show the error, and how that playerHatchDebounce table is builded. Cause under the SeverSide context you are handling this script, that table wont work if you are not storing a key per player
its the same error again and how do you fix an infinite yield error?
Show the error exactly as it shows in output… theres no way we can know what the error is if you dont show it…
And again, show how you are populating the playerHatchDebounce
table cause that table needs to have a Key per Player, otherwise your script is nonsense
Other stuff than can be fixed later is stuff like that. Theres no need for you to require that Module more than once. Pointless of doing that everytime a Player triggers the ProximityPrompt.
Again, this script looks like you are trying to migrate from ClientSide to ServerSide by just pasting it on server, but you still trying to handle it as a ClientScript
An infinite yield error is a function that yields forever. I need the output log of the error to help you.
Also, it seems that you are currently trying to index nil with the PlayerRemoving event which means that the variable Player is nil(null). To solve it make a variable named Player and set it as Players(service) or change that Player variable to the player named variable.
I would suggest you read the progress of replies in the thread cause I already explained all those issues along with other ones. Its obvious that player variable was not a player instance, not necesary “nil” cause it was holding the PlayerService…
EggViwerSystem GUI component or whaterver it is, doesnt exist inside PlayerGui when you tried to access it. But its not related with your current issue
over on
local eggData = require(egg.Data)
your confusing me
I know I was trying to answer why the error is repeating itself. The table isn’t nil but the Player variable is. The error has the event listed, not the table. I was trying to address that.