Problem with this script

What is the thing supposed to do that’s it’s not doing? Sorry for the weird wording, i needed at least 30 letters

If you are talking about what the script is supposed to do if touch ended, and it was a character, and there are no more characters in the part then it is supposed to teleport a random player to a part called “ButtonArea”

Yes, but what is it not doing?

exactly that. not teleporting the random player which has to be me because I am the only player

Ok so have you tried using “Print Checkpoints”?

I have never heard of that.

(this is so I have 30+ characters)

does it mean adding print after each if statement to see if it worked?

1 Like

Yes thats what it is. You should use it to see where your script stops working. But don’t just print random stuff, print values to make sure they get passed along like printing random player to make sure it actually gets a player. Also you cant just use game:GetService(“Players”) to get the table of players, you need to use the game:GetService(“Players”):GetPlayers() function.

Wait a minute… does Touch Ended work if the player teleported out?

I just noticed that the touch ended will keep being called just because the player is walking, and the only way to fix that is to make the part much bigger but that is not an option for me so I might not be able to do this script. btw, @RedStoneGlenn, Thank you for helping if I could reward you I would but I have nothing to reward you with.

i will not deleted this script though just incase somebody finds a way that fixes this. btw, here is the current script:

local parent = script.Parent
local parts = parent:GetTouchingParts() -- get all the parts that are touching the part
local players = game:GetService("Players"):GetPlayers()

function Touching(part) -- function
	print("Touch Ended")
	if part.Parent:FindFirstChild("Humanoid") then -- check to see if the part that left has Humanoid as a sibling
		for i, v in pairs(parts) do -- put the parts variable into a for loop
			if v.Parent:FindFirstChild("Humanoid") then --double check if the part is part of the character
				if v == nil then -- check to see if there are still characters touching the part
					local randomPlayer = math.random(#players) -- get a random player
					local randomCharacter = randomPlayer.Character or randomPlayer.CharacterAdded:Wait() --get the character of the random player
					randomCharacter.HumanoidRootPart.CFrame = game.Workspace.ButtonArea -- teleport the player to the ciontrol room (aka button area)
				end	
			end
		end
		
	end
end

parent.TouchEnded:Connect(Touching) -- make the function start when a part stops touching the part

Thank you! I’m glad to help. Getting solutions is my favorite reward so we might could still fix this. Can you send me a video of what you are trying to do, that might help me.

1 Like

Here is the video clip:


at the end when I leave the area with the buttons it is supposed to teleport a random player back there because there always supposed to be someone in there

also, you get the titles by joining groups which you can learn how to do here:

1 Like

I just realized how laggy the recording is, sorry

Oh, It’s not going to work because you are already being teleported or something like that, instead of testing out 1 player, go to test and press start server or something like that and choose 2 people. That should probably help. Also the extra people should just be you. So it’s not like anyone can join

I wont be able to test multiplayer, I am very laggy.

I did find a way around this script though, making it so there are teams, so I can see how many players are on the team instead of seeing how many players are touching a part making it much less complicated. I am still working on it and it has an error but I think this one will be easier to fix.

@RedStoneGlenn
Done! The code works now. this is the final code, with a new parent of workspace:

wait(10)
local playersOnTeam = game:GetService("Teams").Murderers:GetPlayers()
local numberPlayersOnTeam = #playersOnTeam
local players = game:GetService("Players"):GetPlayers()
while true do
	wait(0.1)
	if numberPlayersOnTeam == 0 then
		for i, v in pairs(players) do
			local NewV = v.PlayerGui.Messages.NewMurderer
			NewV.Visible = true
			NewV.Text = "Randomly Selecting New Murderer... (5)"
			wait(1)
			NewV.Text = "Randomly Selecting New Murderer... (4)"
			wait(1)
			NewV.Text = "Randomly Selecting New Murderer... (3)"
			wait(1)
			NewV.Text = "Randomly Selecting New Murderer... (2)"
			wait(1)
			NewV.Text = "Randomly Selecting New Murderer... (1)"
			wait(1)
			NewV.Text = "Done!"
			wait(0.5)
			NewV.Visible = false
			NewV.Text = "Randomly Selecting New Murderer... (5)"
		end
		local function selectPlayer()
			players = game.Players:GetPlayers()
			local selected = players[math.random(1,#players)]
			return selected
		end
		randomPlayer = selectPlayer()
		if randomPlayer and randomPlayer.Character then
			local part = game.Workspace.ButtonArea
			randomPlayer.Character.HumanoidRootPart.CFrame = part.CFrame
			randomPlayer.Team = game.Teams.Murderers
		end
		break
	end
end

but since you helped a lot, i will give you the solution but you just need to say what the solution is so anybody who has the same problem will also have a solution.

2 Likes

No, It’s fine you solved it so solution your own post! I’m glad I was here to help though! I know it can be kind of tough to figure a bug out by yourself. I can drive me nuts sometimes! Glad you figured out!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.