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

player not teleporting to the map in Piggy pls help and tell me whats wrong?

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.and i tried to fix it but nothing is happening here is my code please tell me if i may have missed or mistyped. Thanks! so here is the code 1 --Game Logic script--------------------------------------------------------------- local Round = require(script.RoundModule)

Round.Intermission(60)
 
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")

2 -- RoundModule script---------------------------------------------------------

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

1 comment

0

Did it throw any errors at you?

1 answer

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