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

It won't position the character?

Asked by 4 years ago

So if the player is a demon, it would position them to the spawn, but if they're a human, they won't be positioned to a random spawn

function module:SpawnCharacter(plr,char,data)
    local D = math.random(1,2)
    local S = math.random(1,6)
    print("D and S Active!")
    local HRP = char:FindFirstChild("HumanoidRootPart")
    if data.Race.Value == "Demon" then
        if D == 1 then
            local NewCFrame1 = game.Workspace.Spawns.DemonSpawn1.CFrame
            HRP.CFrame = NewCFrame1
            print("Spawned Char")
        elseif D == 2 then
            local NewCFrame2 = game.Workspace.Spawns.DemonSpawn2.CFrame
            HRP.CFrame = NewCFrame2
            print("Spawned Char")
    else
            if S == 1 then
                local NewCFrame3 = game.Workspace.Spawns.SlayerSpawn1.CFrame
                HRP.CFrame = NewCFrame3
                print("Spawned Char")
            elseif S == 2 then
                local NewCFrame4 = game.Workspace.Spawns.SlayerSpawn2.CFrame
                HRP.CFrame = NewCFrame4
                print("Spawned Char")
            elseif S == 3 then
                local NewCFrame5 = game.Workspace.Spawns.SlayerSpawn3.CFrame
                HRP.CFrame = NewCFrame5
                print("Spawned Char")
            elseif S == 4 then
                local NewCFrame6 = game.Workspace.Spawns.SlayerSpawn4.CFrame
                HRP.CFrame = NewCFrame6
                print("Spawned Char")
            elseif S == 5 then
                local NewCFrame7 = game.Workspace.Spawns.SlayerSpawn5.CFrame
                HRP.CFrame = NewCFrame7
                print("Spawned Char")
            elseif S == 6 then
                local NewCFrame8 = game.Workspace.Spawns.SlayerSpawn6.CFrame
                HRP.CFrame = NewCFrame8
                print("Spawned Char")
            end 
        end
    end
end

2 answers

Log in to vote
0
Answered by 4 years ago

Aw man, you were so close. The reason nothing happens if you are a human is because you need an end after the third if statement. Your code should look like this.

function module:SpawnCharacter(plr,char,data)
    local D = math.random(1,2)
    local S = math.random(1,6)
    print("D and S Active!")
    local HRP = char:FindFirstChild("HumanoidRootPart")
    if data.Race.Value == "Demon" then
        if D == 1 then
            local NewCFrame1 = game.Workspace.Spawns.DemonSpawn1.CFrame
            HRP.CFrame = NewCFrame1
            print("Spawned Char")
        elseif D == 2 then
            local NewCFrame2 = game.Workspace.Spawns.DemonSpawn2.CFrame
            HRP.CFrame = NewCFrame2
            print("Spawned Char")
        end
    else
         if S == 1 then
             local NewCFrame3 = game.Workspace.Spawns.SlayerSpawn1.CFrame
             HRP.CFrame = NewCFrame3
             print("Spawned Char")
         elseif S == 2 then
             local NewCFrame4 = game.Workspace.Spawns.SlayerSpawn2.CFrame
             HRP.CFrame = NewCFrame4
             print("Spawned Char")
         elseif S == 3 then
             local NewCFrame5 = game.Workspace.Spawns.SlayerSpawn3.CFrame
             HRP.CFrame = NewCFrame5
             print("Spawned Char")
         elseif S == 4 then
             local NewCFrame6 = game.Workspace.Spawns.SlayerSpawn4.CFrame
             HRP.CFrame = NewCFrame6
             print("Spawned Char")
         elseif S == 5 then
             local NewCFrame7 = game.Workspace.Spawns.SlayerSpawn5.CFrame
             HRP.CFrame = NewCFrame7
             print("Spawned Char")
         elseif S == 6 then
             local NewCFrame8 = game.Workspace.Spawns.SlayerSpawn6.CFrame
             HRP.CFrame = NewCFrame8
             print("Spawned Char")
        end
    end
end

The reasoning is that the "else" statement that should be for the first if statement was actually for the third, the false indentation probably threw you off. Good luck with your game.

0
Thank you! It works. This makes a lot more sense. I had no idea what the problem was. Justingamer700 114 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You didn't give much information about your problem, like errors, hierarchy, etc. But if all you're trying to do is teleport them, then you should be able to use:

local NewPos2 = game.Workspace.Spawns.DemonSpawn2.Position
    HRP.Position = NewPos2

Obviously, you may need to adjust it if the part you're teleporting to is tall enough that your character gets stuck inside it.

Answer this question