Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Been having trouble with making a war tycoon and got lots of errors can any body fix my crappy code?

trying to make a tycoon

got error:

  22:29:30.160 - ServerScriptService.ServerMain:16: attempt to index local 'Tycoon' (a nil value)
22:29:30.161 - Stack Begin
22:29:30.162 - Script 'ServerScriptService.ServerMain', Line 16
22:29:30.163 - Stack End

and this is the code:

function FindEmptyTycoon()
	
	for i,v in pairs(workspace.Tycoons.Tycoon1.RightTycoon:GetChildren()) do
		if v.TycoonInfo.Owner.Value == nil then
			return v
			
		end
		return nil
	end
	
end

game.Players.PlayerAdded:Connect(function(Player)
	local Tycoon = FindEmptyTycoon()
	
	Tycoon.TycoonInfo.Owner.Value = Player
	
	local Money = Instance.new("IntValue")
	Money.Name = Player.Name
	Money.Value = 50
	Money.Parent = game.ServerStorage.PlayerMoney
	
end)

1 answer

You're not returning anything bud. Which is why tycoon is a nil value. Instead, make a variable, set it, and return the contents of that variable.

local foundtycoon

function FindEmptyTycoon()
   for i,v in pairs(workspace.Tycoons.Tycoon1.RightTycoon:GetChildren()) do
	if v.TycoonInfo.Owner.Value == nil then
	        foundtycoon = v
	end
   end
   return foundtycoon
end

sorry for any crappy formatting or indenting im on mobile

2 comments

0

thanks for the info but thats not the proplem the proplem is at line 16

0

i got the same error

This discussion is preserved as it was. New answers, comments, and votes are closed.