Is my studio going crazy? Should I reinstall it? Or did I miss some small thing that blocked my entire code?
Please help me. I cannot continue working on my game if a mediocre error stops me. (well not quite since that is kinda the first step of the entire system)
Usually this happens because the actual function binding part never gets ran. What happens before you try running this part of the code? Have you ensured that the line right before the connection gets printed?
Right before your game.Players.PlayerAdde:Connect() line add a print(“player added”) and make sure that runs. Note that a wait() before it at all might let you join the server before the code actually starts looking for the players that are joining.
Basically, there should be no waits before this code. And it should print something directly above it immediately
That means your code is never getting there. Does your module have an infinite loop or something? If it doesn’t return the rest of your code will never run.
If you are testing in “Play Solo” mode, then you are probably experiencing the Player connecting to the game before the server-side scripts are run. This means the Player has already joined the game by the time the Script establishes the PlayerAdded event connection and therefore never fires.
In order to counteract this, you could call the function manually passing in any existing players at the run-time:
local Players = game:GetService("Players")
function onPlayerAdded(player)
end
for _, player in Players:GetPlayers() do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Like i said, I added prints in the module. Its right in the first line, so no infinite loop should happen.
local plot = {}
plot.Random = Random.new()
local x = {}
local y = 200
local z = 300
local FIRST_OFFSET = 200
local function fillTable()
for i=FIRST_OFFSET, 10000, 100 do
wait()
if not table.find(x, i) then
table.insert(x, i)
end
end
end
fillTable()
function plot.new(player:Player)
print("Called")
local num = 1
local chosen = x[num]
table.remove(x, 1)
local part = Instance.new("Part", game.ReplicatedStorage.Plots)
part.Anchored = true
part.Size = Vector3.new(50, 1, 50)
part.TopSurface = Enum.SurfaceType.SmoothNoOutlines
part.BottomSurface = Enum.SurfaceType.SmoothNoOutlines
part.Position = Vector3.new(chosen, y, z)
local tag = Instance.new("IntValue", part)
tag.Name = "Position"
tag.Value = chosen
local plrValue = Instance.new("StringValue", part)
plrValue.Name = "Player"
plrValue.Value = player and player.Name or "LOL"
end
return plot
That fill table function with the wait is going to take minutes. You’re doing a lot there. The player added code won’t work until that’s done. [oops. Didn’t notice you were incrementing by hundreds. Not minutes,]
You can remove that wait. It’s a small enough loop you’re just adding delay unnecessarily (unless for some reason you need to specifically control the timing). My initial estimate was off because I didn’t notice the amount you were incrementing by. But any waits before your player added code can make it miss you while testing.