Is there something wrong with this script?

The problem is that blocks spawn, and only one person can be on one block, but it allows two persons to be in one block.

["Selfish Mode"] = {
		ImageId = "rbxassetid://7885695936",
		InstructionText = "You are the owner of the block you stand on, make others cry!",
		CountdownTimer = 7,
		CustomFunctions = {
			startGame = function(args)
				for _, block in pairs(args.NumberBlockWorkspace:WaitForChild("Blocks"):GetChildren()) do
					if block then
						local newObject = block:FindFirstChild("PlayerStanding") or Instance.new("ObjectValue", block)
						newObject.Name = "PlayerStanding"
					end
				end
			end,
			startRound = function(args)
				coroutine.resume(coroutine.create(function()
					local regions = {}
					local rightfulPlayers = {}

					local assignedBlocks = {}
					local assignedPlayers = {}
					for _, block in pairs(args.NumberBlockWorkspace:WaitForChild("Blocks"):GetChildren()) do
						if block then
							local region3 = Region.new(block.CFrame + Vector3.new(0,5,0), block.Size + Vector3.new(0,11,0))

							regions[block] = region3
							rightfulPlayers[block] = false
						end
					end
					repeat
						for _, player in pairs(Players:GetPlayers()) do
							local survivor = player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") and player.Character:FindFirstChild("Survivor_") 
							if survivor then
								local rayParams = RaycastParams.new()
								rayParams.FilterDescendantsInstances = {args.NumberBlockWorkspace:WaitForChild("Blocks")}
								rayParams.FilterType = Enum.RaycastFilterType.Whitelist
								local raycastResult = workspace:Raycast(player.Character.HumanoidRootPart.Position, Vector3.new(0,-20,0), rayParams)
								if raycastResult and raycastResult.Instance then
									local block = raycastResult.Instance

									if not rightfulPlayers[block] then
										rightfulPlayers[block] = player
										survivor.Value = block
									elseif rightfulPlayers[block] ~= player then
										survivor.Value = nil
									else
										rightfulPlayers[block] = player
										survivor.Value = block
									end
								elseif survivor.Value then
									rightfulPlayers[survivor.Value] = nil
									survivor.Value = nil
								end
							end
						end
						for block, region in pairs(regions) do
							if block then

								local turnOn = nil
								for _, player in pairs(Players:GetPlayers()) do
									local survivor = player and player.Character and player.Character:FindFirstChild("Survivor_")
									if survivor and survivor.Value == block then
										turnOn = player
										break
									end
								end

								block.PlayerStanding.Value = turnOn
								if block.CanCollide then
									local surfaceUI = block:WaitForChild("SurfaceGui")
									if turnOn then
										block.SurfaceGui.Frame.Visible = false
										block.SurfaceGui.Frame2.Visible = true
									else
										block.SurfaceGui.Frame.Visible = true
										block.SurfaceGui.Frame2.Visible = false
									end
								end
							end
						end
						wait(.1)
					until args.Mode.Parent.Status.Value == "BlockDisappearing"
					for block, region in pairs(regions) do
						if block then
							local surfaceUI = block:WaitForChild("SurfaceGui")
						end
					end
				end))
			end,
		}

The thing is, you gotta run the code first. It’s not like the whole world will collapse if you don’t see what happens first or not know what’s not working as intended.

To be honest, I dont think theres anything wrong.

2 Likes