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

What and How is this a userdata value?

Asked by 6 years ago

I'm trying to make it so you randomly spawn in any of the spawnpoint setup but it is saying that spawns is a user data value

variables / values

local maps = serverstorage:WaitForChild("maps")
local mapholder = game.Workspace:WaitForChild("MapHolder")
local allmaps = maps:GetChildren()
mapholder:ClearAllChildren()
local newmap = allmaps[math.random(1, #allmaps)]
newmap.Parent = game.Workspace
spawnsmodel = newmap:WaitForChild("spawns")
local spawns = spawnsmodel:FindFirstChild("spawnpoint")

spawning people

    for i, Player in pairs(people) do
        if Player and Player.character then
            local torso = Player.Character:WaitForChild("Torso")
            local spawnindex = math.random(1, #spawns)
            local spawner = spawns[spawnindex]
            if spawner and torso then
                table.remove(spawns,spawnindex)
                torso.CFrame = CFrame.new(spawner.position + Vector3.new(0,3,0))
                matchtag = Instance.new("StringValue")
                matchtag.Name = "MatchTag"
                matchtag.Parent = Player.character
                end

                    local backpack = Player:FindFirstChild("Backpack")
                    if backpack then
                        if Player == Chuini then
                            axe = serverstorage:WaitForChild("axe"):clone()
                            axe.Parent = backpack
                            game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 14
                            game.lighting.FogEnd = 10000
                            game.Players.LocalPlayer.Character.Humanoid.MaxSlopeAngle = 85
                            if game.Workspace.SprintScriptImporter.SprintScript.runing == true then
                                game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
                            end
                            event:FireAllClients("Class", "Chuini")
                            end
                        else
                            game.Lighting.FogEnd = 50
                            event:FireAllClients("Class", "Tourist")
                        end
                    end
                end
    end
end

output 13:11:23.642 - ServerScriptService.mainscript:212: attempt to get length of local 'spawns' (a userdata value) 13:11:23.644 - Stack Begin 13:11:23.645 - Script 'ServerScriptService.mainscript', Line 212 13:11:23.685 - Stack End

1 answer

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago

The reason this is erroring is because you are treating the value of spawns as a table when it isn't. To fix this on line 8 you should get the children of that model so you get a table, then where you are setting spawn index you can get # from that table without it erroring.

local maps = serverstorage:WaitForChild("maps")
local mapholder = game.Workspace:WaitForChild("MapHolder")
local allmaps = maps:GetChildren()
mapholder:ClearAllChildren()
local newmap = allmaps[math.random(1, #allmaps)]
newmap.Parent = game.Workspace
spawnsmodel = newmap:WaitForChild("spawns")
local spawns = spawnsmodel:GetChildren() --GetChildren() returns a table
Ad

Answer this question