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

Why this code keeps error and in the dev console it says : a nil value? [Answered]

Im trying to make a minigame that only have 1 map for now and its speed run. The problem is it keeps saying a nil value until I have no idea. So I need a help here. Here is the dev console : [I use a link because I can't put my screenshot here by using trello] https://trello.com/c/owZ7gkSZ/27-a-nil-value-problem-screenshot

And the script :

--start
local Player1 = game.Players.PlayerAdded:wait()

--variables
Map1 = game.ServerStorage.Maps.Arena1
NotificationBoard = game.Workspace.StatusBar.Text
TpEnabled = false

-- Scripts
--TpScript
--Reciver Vars
Spawn1o = 0
Spawn2o = 0
Spawn3o = 0
Spawn4o = 0
Spawn5o = 0
Spawn6o = 0
enabled = true
Reciver = game.Workspace.Spawn.Spawn1
--Main Tp Script
game.Workspace.TpSender.Touched:connect(function(part)
local hum = part.Parent:FindFirstChild("Humanoid")
	if hum~=nil then 
		if TpEnabled == true then
		if enabled == true then 
			enabled = false
			local t = part.Parent:FindFirstChild("Torso")
			local t2 = Reciver
			t.CFrame = CFrame.new(t2.Position.x, t2.Position.y+4, t2.Position.z)
			Spawn1o = Spawn1o +1
			wait(1)
			enabled = true
			if Spawn1o == 4 then
				Reciver = game.Workspace.Spawn.Spawn2
				if Spawn2o == 4 then
				Reciver = game.Workspace.Spawn.Spawn3
				    if Spawn3o == 4 then
				    Reciver = game.Workspace.Spawn.Spawn4
				        if Spawn4o == 4 then
				        Reciver = game.Workspace.Spawn.Spawn5
				            if Spawn5o == 4 then
				            Reciver = game.Workspace.Spawn.Spawn6
				            end
				            end
				        end
				    end
				end
			end
		end
	end
end)
--WinnerDetector
game.Workspace.WinnerDetector.Touched:connect(function(hit)
    local Plr = game.Players:GetPlayerFromCharacter(hit.Parent)	
	game.ReplicatedStorage.Variables.WinnerFound.Value = true
	game.ReplicatedStorage.Variables.Winner.Value = Plr.Name
	hit.Parent.Humanoid.Health = 0
end)

--Gamemode Changer
while true do
wait(5)
Player1.PlayerGui.WinnerGui.TextBox.Text = ("Please Wait")
NotificationBoard.Value = ("Please Wait")
print("Wait60")
wait(60)
NotificationBoard.Value = ("Current Map : SpeedRun") 
NotificationBoard.Value = ("Current Map : SpeedRun")
print("LoadMap")
wait(5)
NotificationBoard.Value = ("Loading...")
NotificationBoard.Value = ("Loading...")
wait(2)
Map1:clone().Parent = game.Workspace
Player1.PlayerGui.WinnerGui.TextBox.Text = ("Teleporting Players")
TpEnabled = true
NotificationBoard.Value = ("Game In Progress")
NotificationBoard.Value = ("Game In Progress")
Player1.PlayerGui.WinnerGui.TextBox.Text = ("Game In Progress")
if game.ReplicatedStorage.Variables.WinnerFound.Value == true then
game.ReplicatedStorage.Variables.WinnerFound.Value = false
game.Workspace.Map:destroy()
TpEnabled = false
Spawn1o = 0
Spawn2o = 0
Spawn3o = 0
Spawn4o = 0
Spawn5o = 0
Spawn6o = 0
NotificationBoard.Value = "Game Ended"
NotificationBoard.Value = "Game Ended"
Player1.PlayerGui.WinnerGui.TextBox.Text = "Winner :" ..game.ReplicatedStorage.Variables.Winner.Value
wait(10)
game.ReplicatedStorage.Variables.Winner.Value = "None"
Player1.PlayerGui.WinnerGui.TextBox.Text = "Winner :" ..game.ReplicatedStorage.Variables.Winner.Value

end
end

3 comments

0

Line 2 - It's not gonna work that way, You gotta bind a function to player added event

0

The problem is the line 61. See the dev console screenshot

0

Anyway thanks for that tips. Because I just noticed that line 2 is a bit weird and glitchy before I edit the script into the script you see now.

1 answer

✓ Accepted answer

As I see it, your script is flawed that, even if we do give an answer... it will not work with the rest of your coding... as such, i suggest you try to make it so that everything is coherent... for example:

The map is still in ServerStorage, to move it you should use:

local mapholder = Instance.new("Model", game.Workspace)
mapholder.Name = "CurrentMap"

game.ServerStorage.Maps.Arena --[[ error ]]

Your map will now error because the map has a NumberValue in a line of code that has a String, as such you will need to use FindFirstChild()

local mapholder = Instance.new("Model", game.Workspace)
mapholder.Name = "CurrentMap"

local mapa = game.ServerStorage.Maps:FindFirstChild("Arena1")
mapa.Parent = mapholder

I could keep going on, but I will instead recommend you to some ROBLOX wiki pages that you should learn:

http://wiki.roblox.com/index.php?title=Loops

http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions&redirect=no#pairs

http://wiki.roblox.com/index.php?title=API:Class/Instance/FindFirstChild

After you have done this, you should start from scratch, and attempt to create a smooth code.. if you still cannot do this, pm me on roblox (Username: Taryo)

~ Taryo

Edit:

Removed CFrame and Vector3 from recommended list, you can still view them here:

http://wiki.roblox.com/index.php?title=CFrame http://wiki.roblox.com/index.php?title=Vector3

6 comments

0

Thanks alot for the help.

0

You're welcome... The issue was that even though some of your code worked... it wouldn't work with the rest of your code. I recommended you to some places, but also make sure to review functions here: http://wiki.roblox.com/index.php?title=Function

0

And why do you give me about CFrames and vector 3? Is it about the teleporter? The teleporter doesn't work? Cause Im a bit confused that you give me that:/

0

Oops, I didn't mean to add CFrame to that list, that was for another person, also I added Vector3 because it is typically best to use them inside of CFrame. perhaps since I was thinking of CFrame I added it to the list? I'll edit it.

0

oh ok. Thanks for editing it.

0

And, I almost forget to ask you about the teleporter, about the Reciver Variable cause it look a bit weird and I have a bad feeling about it.

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