Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Player Join Server Error?

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)

2 comments

0

Where is this script located?

0

The script is located in game.Workspace["Gameplay Mechanics"].PlayerJoinScript

1 answer

✓ Accepted answer

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.

3 comments

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.

0

Thanks! I messed up the script. It's fixed now.

0

The script works perfectly now, thanks for the help.

This discussion is preserved as it was. New answers, comments, and votes are closed.