Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

0
Line 2 - It's not gonna work that way, You gotta bind a function to player added event buoyantair 123 — 8y
0
The problem is the line 61. See the dev console screenshot krisxxxz 45 — 8y
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. krisxxxz 45 — 8y

1 answer

Log in to vote
1
Answered by
Scarious 243 Moderation Voter
8 years ago

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

0
Thanks alot for the help. krisxxxz 45 — 8y
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 Scarious 243 — 8y
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:/ krisxxxz 45 — 8y
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. Scarious 243 — 8y
View all comments (2 more)
0
oh ok. Thanks for editing it. krisxxxz 45 — 8y
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. krisxxxz 45 — 8y
Ad

Answer this question