I'm currently trying to remake the game "Piggy" for my own friends and I enjoyment and I searched online and got my hands on a template with some codes that needs to be self-typed and recently, I got stuck at the teleport part of the code.

Where the players should be teleported to the map while the piggy to the waiting room. There is two variation of the problem I have faced.

When tested out in Roblox Studio, With One player The Player got chosen as Piggy as there's is only one player.

With two or more player

The expected output should be one be piggy and one be player and piggy be teleported to the waiting room and the player to the map. My problems I faced is that sometimes both the players remains at the spawn and didn't get teleported or one player got chosen as piggy and was teleported but the player is not teleported to the map.

My Teleportation consists of two scripts,one module script and one normal script.

--Game Logic(A normal script inside ServerScriptService)***
local Round = require(script.RoundModule)

Round.Intermission(25)

local chosenChapter = Round.SelectChapter()


local clonedChapter = chosenChapter:Clone()

clonedChapter.Name = "Map"

clonedChapter.Parent = game.Workspace

local contestants = {}

for i,v in pairs(game.Players:GetPlayers()) do
    if not v:FindFirstChild("InMenu") then
        table.insert(contestants,v)
    end
end
 
 
local chosenPiggy = Round.ChoosePiggy(contestants)

for i,v in pairs(contestants) do 
    if v == chosenPiggy then
table.remove(contestants,i)
 
 	else
 
 	    game.ReplicatedStorage.ToggleCrouch:FireClient(v,true)
 
 	end
end
 
 Round.DressPiggy(chosenPiggy)
 
 Round.TeleportPiggy(chosenPiggy)

 Round.TeleportPlayers(contestants, clonedChapter.PlayerSpawns:GetChildren())
 
 Round.InsertTag(contestants,"Contestant")
 
 Round.InsertTag({chosenPiggy},"Piggy")
--Module Script(A module script inside ServerScriptService)
 local module = {}
 
local status = game.ReplicatedStorage:WaitForChild("Status")
 
 function module.Intermission(length)
 	for i =length,0,-1 do 
      status.Value = "Next round starts in "..i.." seconds"
 		wait(1)
 	end
 end
 
 function module.SelectChapter()
 	local rand = Random.new()
 	local chapters = game.ReplicatedStorage.Chapters:GetChildren()
 	local chosenChapter = chapters[rand:NextInteger(1,#chapters)]
 
 return chosenChapter
 end
 
 
 function module.ChoosePiggy(players)
 
 local RandomObj = Random.new()
 local  chosenPiggy = players[RandomObj:NextInteger(1,#players)]
 
 return chosenPiggy
 
 end
 
 function module.DressPiggy(piggy)
 local character = game.ServerStorage.Piggy:Clone()
 character.Name = piggy.Name

 piggy.Character = character
 
 character.Parent = workspace
 
 end
 
 function module.TeleportPiggy(player)
 if player.Character then 
 
 	player.Character.Humanoid.WalkSpeed = 14
 	
 	local bat = game.ServerStorage.Tools.PiggyBat:Clone()
 	bat.Parent = player.Character
 
 if player.Character:FindFirstChild("HumanoidRootPart")then
 	player.Character.HumanoidRootPart.CFrame = game.Workspace.WaitingRoom.PiggyWaitingSpawn.CFrame + Vector3.new(0,5,0)
 end
 end
 end
 
 function module.TeleportPlayers(players,mapSpawns)
   for i, player in pairs(players)do
    if player.Charcter then 
 	local character = player.Character
 	
	if character:FindFirstChild("HumanoidRootPart") then
		
		player.Character.Humanoid.WalkSpeed = 16
         local rand = Random.new()
         player.Character.HumanoidRootPart.CFrame = mapSpawns[rand:NextInteger(1,#mapSpawns)].CFrame + Vector3.new(0,10,0)
 end		
    end    
 	end
 end
 
 function module.InsertTag(contestants,tagName)
 for i, player in pairs(contestants)do
 	local Tag = Instance.new("StringValue")
     Tag.Name = tagName
     Tag.Parent = player
end
 
 end

 return module 


I have the map stored inside the replicatedStorage, all the scripts inside the ServerScriptService and the Piggy Model in the server Storage.

I would like to thanks anyone in the community would be able to point out what went wrong and what I may have missed or mistyped. Thanks!

5 comments

0

Hello, a friend of MiniToon’s here. It’s very cool to see his game reach out to so many people! But AlvinBlox’s tutorials aren’t the best to follow for such a large mechanic like Piggy.

0

I see, but is there any problem with the codes though? I just cannot find the mistake despite it works inside Alvin's Vids.

0

That’s what he’s notoriously known for. I would love to take a look, though his code is quite different from the code within Piggy, it makes it a bit more tedious to traverse through, the biggest issue here is that you’ve formatted everything into inline code. You need to paste the raw code in a Lua Code Block to have it present itself as a script properly.

0

hmm your script is correct but can you give me Event handling script or i have no clue that whats wrong

0

i got this problem before too i checked my event handing did some corrections and it worked