I’m currently working on a sandbox tycoon, but I’m having trouble with one of the simplest parts. I am trying to make the system that gives the user a tycoon, but for whatever reason it returns nil. This is the code:
local Tycoons = workspace.TycoonHolder
local Event = game:GetService('ReplicatedStorage').Event
local Players = game:GetService('Players')
function GetAvalibleTycoon()
wait(1)
for _,v in pairs(Tycoons:GetChildren()) do
if v then
if v.Info.Owner.Value ~= nil then
print(v.Name)
return v
end
end
end
end
Players.PlayerAdded:connect(function(Player)
local Tycoon = GetAvalibleTycoon()
wait()
if Tycoon then
print(3)
local Info = Tycoon.Info
Info.Owner.Value = Player
print(4)
end
end)
16:38:20.836 - ServerScriptService.TycoonHandlerServer:23: attempt to index local ‘Tycoon’ (a nil value)
16:38:20.836 - Stack Begin
16:38:20.837 - Script ‘ServerScriptService.TycoonHandlerServer’, Line 23
16:38:20.837 - Stack End