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 5 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

01function module:SpawnCharacter(plr,char,data)
02    local D = math.random(1,2)
03    local S = math.random(1,6)
04    print("D and S Active!")
05    local HRP = char:FindFirstChild("HumanoidRootPart")
06    if data.Race.Value == "Demon" then
07        if D == 1 then
08            local NewCFrame1 = game.Workspace.Spawns.DemonSpawn1.CFrame
09            HRP.CFrame = NewCFrame1
10            print("Spawned Char")
11        elseif D == 2 then
12            local NewCFrame2 = game.Workspace.Spawns.DemonSpawn2.CFrame
13            HRP.CFrame = NewCFrame2
14            print("Spawned Char")
15    else
View all 43 lines...

2 answers

Log in to vote
0
Answered by 5 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.

01function module:SpawnCharacter(plr,char,data)
02    local D = math.random(1,2)
03    local S = math.random(1,6)
04    print("D and S Active!")
05    local HRP = char:FindFirstChild("HumanoidRootPart")
06    if data.Race.Value == "Demon" then
07        if D == 1 then
08            local NewCFrame1 = game.Workspace.Spawns.DemonSpawn1.CFrame
09            HRP.CFrame = NewCFrame1
10            print("Spawned Char")
11        elseif D == 2 then
12            local NewCFrame2 = game.Workspace.Spawns.DemonSpawn2.CFrame
13            HRP.CFrame = NewCFrame2
14            print("Spawned Char")
15        end
View all 43 lines...

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 — 5y
Ad
Log in to vote
0
Answered by 5 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:

1local NewPos2 = game.Workspace.Spawns.DemonSpawn2.Position
2    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