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

Player Join Server Error?

Asked by 9 years ago

So I created a script that was intended to create a part based on whichever random number is picked from math.random. There are no errors from Output.

The problem is that there are not any new parts created when I join the game (through the Roblox Player and through Studio (I'm new to this part of scripting so I don't know if you're character loads before the scripts as if it was single player mode).

Here's the script I have, thanks for any possible help.

Players = game:GetService("Players")

MyPart1 = Instance.new("Part", workspace)
MyPart2 = Instance.new("Part", workspace)
MyPart3 = Instance.new("Part", workspace)

function PlayerJoin(Player)
    math.random(1,3)
        if math.random == 1 then
            print(Player.Name .. "has entered the game")
            print (MyPart1)
            MyPart1.Name = "Example 1"
            MyPart1.BrickColor = BrickColor.new("Bright blue")
            MyPart1.Position = Vector3.new(100,100,100)
            MyPart1.Size = Vector3.new(30,30,30)    
        end
        if math.random == 2 then
            print(Player.Name .. "got TKO'd by JOHN CENA!!!")
            print (MyPart2)
            MyPart2.Name = "Example 2"
            MyPart2.BrickColor = BrickColor.new("Bright blue")
            MyPart2.Position = Vector3.new(200,200,200)
            MyPart2.Size = Vector3.new(50,50,50)    
        end
        if math.random == 3 then
            print(Player.Name .. "is in the WWE Superslam!!!")
            print (MyPart3)
            MyPart3.Name = "Example 3"
            MyPart3.BrickColor = BrickColor.new("Sea green")
            MyPart3.Position = Vector3.new(300,300,300)
            MyPart3.Size = Vector3.new(70,70,70)
        end
end

Players.PlayerAdded:connect(PlayerJoin)
0
Where is this script located? iconmaster 301 — 9y
0
The script is located in game.Workspace["Gameplay Mechanics"].PlayerJoinScript LoREMidnight 20 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

No case is running, because you aren't calling math.random. You're comparing the function with the numbers, which is always false.

This should fix it:

Players = game:GetService("Players")

MyPart1 = Instance.new("Part", workspace)
MyPart2 = Instance.new("Part", workspace)
MyPart3 = Instance.new("Part", workspace)

function PlayerJoin(Player)
    local x = math.random(1,3)
        if x == 1 then
            print(Player.Name .. "has entered the game")
            print (MyPart1)
            MyPart1.Name = "Example 1"
            MyPart1.BrickColor = BrickColor.new("Bright blue")
            MyPart1.Position = Vector3.new(100,100,100)
            MyPart1.Size = Vector3.new(30,30,30)    
        end
        if x) == 2 then
            print(Player.Name .. "got TKO'd by JOHN CENA!!!")
            print (MyPart2)
            MyPart2.Name = "Example 2"
            MyPart2.BrickColor = BrickColor.new("Bright blue")
            MyPart2.Position = Vector3.new(200,200,200)
            MyPart2.Size = Vector3.new(50,50,50)    
        end
        if x == 3 then
            print(Player.Name .. "is in the WWE Superslam!!!")
            print (MyPart3)
            MyPart3.Name = "Example 3"
            MyPart3.BrickColor = BrickColor.new("Sea green")
            MyPart3.Position = Vector3.new(300,300,300)
            MyPart3.Size = Vector3.new(70,70,70)
        end
end

Players.PlayerAdded:connect(PlayerJoin)

EDIT: derp, math.random.

1
Might want to make the initial math.random(1,3) a variable and reference that variable when comparing the numbers in the if then statements. M39a9am3R 3210 — 9y
0
Thanks! I messed up the script. It's fixed now. iconmaster 301 — 9y
0
The script works perfectly now, thanks for the help. LoREMidnight 20 — 9y
Ad

Answer this question