How do I do this?

Hey. I came on here today to ask how I can make a part for each player that’s in the Competition (table)

I have done this code but I dont know how I would make a part for each person that’s in the table (hopefully this makes sense)

image

2 Likes

This should work, but you’ve gotta set a parent, add this

PlayerOwnTP.Parent = game.Workspace
1 Like

but i think it only creates 1 part. I need it to create based on how many players are in the competition (table)

1 Like

Try it, if I’m right it creates as many parts as the table’s amount.

1 Like

for some reason it created more then the table

1 Like

Could you provide a script? That way I’d have more intel.

1 Like

alright gimme a sec to do that but when i printed the players in the table it did this

image

I have no idea why it’s like this, it’s something you’ve done with the script that made it like this, I guess.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Assets = ReplicatedStorage:WaitForChild("Assets")
local PushCompetition = Assets:WaitForChild("PushCompetition")
local Events = ReplicatedStorage:WaitForChild("Events")
local GUI = script:WaitForChild("DailyPushWarGUI")

local Remote = PushCompetition:WaitForChild("PushBattle")
local Status = PushCompetition:WaitForChild("Status")

local TimeForStart = 30 -- make 3600 so its 1 hour
local PlayersRequired = 1

local Round = false

local DailyPushBattleHandler = {}

local PlayersInCompetition = {}

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local DailyPushVal = Player:WaitForChild("DailyPushVal")
		
		while task.wait(1) do
			if DailyPushVal.Value <= TimeForStart then
				DailyPushVal.Value = DailyPushVal.Value + 1
			end
			
			if DailyPushVal.Value >= TimeForStart then
				DailyPushVal.Value = 0
				local GUIClone = GUI:Clone()
				GUIClone.Parent = Player.PlayerGui
				
				Character:WaitForChild("Humanoid").Died:Connect(function()
					GUIClone:Destroy()
				end)
				
				task.delay(5, function()
					GUIClone:Destroy()
				end)
				
				--print("start")
				
				Remote.OnServerEvent:Connect(function(Player)
					table.insert(PlayersInCompetition, Player)
				end)
				
				repeat
					task.wait(1)
					Status.Value = "You need atleast "..PlayersRequired.." to start!"
				until #PlayersInCompetition >= PlayersRequired
				
				for i = 15, 1, -1 do
					task.wait(1)
					Status.Value = "Competition Starts In: "..i
				end
				
				Round = true
				
				for i, v in pairs(PlayersInCompetition) do
					print(i, v)
					local PlayerOwnTP = Instance.new("Part")
					PlayerOwnTP.Parent = game.Workspace.Game.PushWar.Spawns
					PlayerOwnTP.Name = "MainGameTP"
					PlayerOwnTP.Anchored = true
					PlayerOwnTP.CanCollide = false

					local StringPlayerVal = Instance.new("StringValue")
					StringPlayerVal.Name = "playerTPPart"
					StringPlayerVal.Parent = PlayerOwnTP
					StringPlayerVal.Value = ""
				end
				
				-- teleport players here and make part shrink
			else
				--print("cant start because timer hasnt reached "..TimeForStart)
			end
		end
	end)
end)

also sorry if the script is written bad. Im not that good of a scripter, still learning

i tried making a daily slap competition kinda like slap battles

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
local Assets = ReplicatedStorage:WaitForChild("Assets")
local PushCompetition = Assets:WaitForChild("PushCompetition")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")

local debounce = false

local Remote = PushCompetition:WaitForChild("PushBattle")

script.Parent.Activated:Connect(function()
	if debounce == false then
		debounce = true
		for i, v in pairs(Character:GetDescendants()) do
			if v:IsA("BodyPosition") then -- so no bugs when getting teleported
				v:Destroy()
			end
		end

		Remote:FireServer()
		HumanoidRP.CFrame = game.Workspace.Game.PushWar.PushWarTP.CFrame
		script.Parent.Parent.Parent:Destroy()
		
		task.wait(3)
		debounce = true
	end
end)

this is also the local script where it fires the remote so i can add them to the table (it was the only way i knew to do it) oh yeah and btw it worked when it was only 1 player but when it was 2 it just started making more

Honestly you could try to make your remote event function in a different place like below it because it is currently just hard to read (imo) right now. Also could you try to print the table itself (PlayersInCompetition) instead?

Also remember to set a CFrame to your part as it seems like it has no position. (Also Instance.new() allows you to list the parent, so you could just have

local PlayerOwnTP = Instance.new("Part", game.Workspace.Game.PushWar.Spawns) 

instead of

					local PlayerOwnTP = Instance.new("Part")
					PlayerOwnTP.Parent = game.Workspace.Game.PushWar.Spawns

Alright, so I made a script in another way. Remove that PlayersInCompetition to begin with, So create a folder in replicated storage called players or whatever you desire, and put your players into that. Use the following scripts in your main script

game.Players.PlayerAdded:Connect(function(plr) --You've already created this so only use the scripts below the character added line
	plr.CharacterAdded:Connect(function(char)
		local user = Instance.new("BoolValue", game.ReplicatedStorage.Players)
		user.Name = char.Name
		plr.CharacterRemoving:Connect(function(playerfolder)
			game.ReplicatedStorage.Players:FindFirstChild(playerfolder.Name):Destroy()
			print("User Deleted out of folder")
		end)
		local PlayersInFolder = game.ReplicatedStorage.Players:GetChildren()
		for i, v in pairs(PlayersInFolder) do
			local PlayerOwnTP = Instance.new("Part")
			PlayerOwnTP.Parent = game.Workspace.Game.PushWar.Spawns
			PlayerOwnTP.Name = "MainGameTP"
			PlayerOwnTP.Anchored = true
			PlayerOwnTP.CanCollide = false

			local StringPlayerVal = Instance.new("StringValue")
			StringPlayerVal.Name = "playerTPPart"
			StringPlayerVal.Parent = PlayerOwnTP
			StringPlayerVal.Value = ""
		end
	end)
end)
1 Like

i did print it, its right here

hmmmmmmm ill try it out thank you


do i do get children here or just leave it like this?

That’s alright, you can leave it there.

image
its still making more then how many players there is