So, basically, I'm having a problem where a player can teleport to the same spawn as another, and when the sheriff dies, it isn't calling the HandleSheriff function. This isn't erroring and I don't know why it isn't working because I took the steps to make it work. I understand this is a long script, so I'll give an index to show where the important parts are.

HandleSheriff function: 38-46

DropTaser function: 48-58

Teleport bit: 111-141

Died function: 145-170

--variables
local replicatedstorage = game:GetService("ReplicatedStorage")
local serverstorage = game:GetService("ServerStorage")
local players = game:GetService("Players")
local dss = game:GetService("DataStoreService"):GetDataStore("PlayerData")
local debris = game:GetService("Debris")
local mapholder = workspace:WaitForChild("MapHolder")
local textupdate = replicatedstorage:WaitForChild("TextUpdate")
local guiprompter = replicatedstorage:WaitForChild("GuiPrompter")
local lastbloxxer = nil
local roundtime = 180
--leaderboard and datastore
players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("IntValue")
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"
	local points = Instance.new("IntValue")
	points.Parent = leaderstats
	points.Name = "Points"
	local wins = Instance.new("IntValue")
	wins.Parent = leaderstats
	wins.Name = "Wins"
	local stats = dss:GetAsync(player.UserId)
	if stats then
		points.Value = stats[1]
		wins.Value = stats[2]
	else
		local savestats = {points.Value, wins.Value}
		dss:SetAsync(player.UserId, savestats)
	end
end)
--update data
players.PlayerRemoving:Connect(function(player)
	local savestats = {player.leaderstats.Points.Value, player.leaderstats.Wins.Value}
	dss:SetAsync(player.UserId, savestats)
end)
--called when sheriff dies
function handlesheriff(bloxxedplayer, character)
	if bloxxedplayer and character then
		local humanoid = character:FindFirstChild("Humanoid")
		local root = character:FindFirstChild("HumanoidRootPart")
		if humanoid and root then
			droptaser(root.Position)
		end
	end
end
--spawns netgun in players torso when they die
function droptaser(position)
	local pickup = serverstorage:WaitForChild("Taser"):WaitForChild("Handle"):Clone()
	pickup.Name = "Pickup"
	pickup.Parent = workspace
	pickup.CFrame = CFrame.new(position)
	pickup.Anchored = true
	pickup.CanCollide = false
	local sparkles = Instance.new("Sparkles", pickup)
	sparkles.SparkleColor = Color3.new(0, 0.5, 1)
	debris:AddItem(pickup, localroundtimer)
end
--rewardplayer function
local function rewardplayer(player, pointsreward, winsreward)
	if player then
		local leaderstats = player:FindFirstChild("leaderstats")
		if leaderstats then
			local points = leaderstats:FindFirstChild("Points")
			local wins = leaderstats:FindFirstChild("Wins")
			if points and wins then
				points.Value = points.Value + pointsreward
				wins.Value = wins.Value + winsreward
			end
		end
	end
end
--loops entire round
while true do
	wait(6)
	--add players to table
	while true do
		wait(1)
		contestants = {}
		for _, player in pairs(players:GetPlayers()) do
			if player and player.Character then
				local humanoid = player.Character:FindFirstChild("Humanoid")
				if humanoid and humanoid.Health > 0 then
					table.insert(contestants, player)
				end
			end
		end
		if #contestants >= 3 then
			break
		else
			textupdate.Value = "Waiting for 3 players..."
		end
	end
	--run intermission
	textupdate.Value = "Intermission..."
	wait(6)
	--choose map
	textupdate.Value = "Choosing a map..."
	wait(3)
	local maps = serverstorage:WaitForChild("Maps"):GetChildren()
	local map = maps[math.random(1, #maps)]:Clone()
	map.Parent = mapholder
	wait(1)
	textupdate.Value = "Starting game..."
	wait(3)
	--choose roles
	repeat bloxxer = players:GetPlayers()[math.random(1, #players:GetPlayers())] wait(1) until bloxxer ~= lastbloxxer
	lastbloxxer = bloxxer
	repeat sheriff = players:GetPlayers()[math.random(1, #players:GetPlayers())] wait(1) until sheriff ~= bloxxer
	--teleport contestants
	for _, player in pairs(contestants) do
		if player and player.Character then
			local humanoid = player.Character:FindFirstChild("Humanoid")
			local root = player.Character:FindFirstChild("HumanoidRootPart")
			if humanoid	and humanoid.Health > 0 and root then
				local spawns = map:WaitForChild("Spawns"):GetChildren()
				local randomspawn = table.remove(spawns, math.random(1, #spawns))
				local isplaying = Instance.new("BoolValue")
				isplaying.Parent = player.Character
				isplaying.Name = "IsPlaying"
				isplaying.Value = true
				if randomspawn and isplaying then
					root.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0, 3, 0))
					player:FindFirstChild("PlayerGui").TextGui.Enabled = false
					player:FindFirstChild("PlayerGui").ShopGui.Enabled = false
					player:FindFirstChild("PlayerGui").SpectateGui.Enabled = false
					if player == bloxxer then
						local sword = serverstorage:WaitForChild("Sword"):Clone()
						sword.Parent = player.Backpack
						guiprompter:FireClient(player, "Role", "Bloxxer")
					elseif player == sheriff then
						local taser = serverstorage:WaitForChild("Taser"):Clone()
						taser.Parent = player.Backpack
						guiprompter:FireClient(player, "Role", "Sheriff")
					else
						guiprompter:FireClient(player, "Role", "Bystander")
					end
				end
				humanoid.Died:Connect(function(bloxxedplayer)
					if bloxxedplayer == sheriff then
						handlesheriff(bloxxedplayer, bloxxedplayer.Character)
					end
				end)
			end
		end
	end
	--main round code
	textupdate.Value = "Round in progress..."
	localroundtimer = roundtime
	while localroundtimer > 0 do
		wait(1)
		localroundtimer = localroundtimer - 1
		activecontestants = {}
		bloxxeractive = false
		for _, player in pairs(contestants) do
			if player and player.Character then
				local humanoid = player.Character:FindFirstChild("Humanoid")
				local isplaying = player.Character:FindFirstChild("IsPlaying")
				if humanoid and humanoid.Health > 0 and isplaying then
					table.insert(activecontestants, player)
					if player == bloxxer then
						bloxxeractive = true
					end
				end
			end
		end
		if #activecontestants <= 1 or not bloxxeractive then
			break
		end
	end
	--create round results
	for _, player in pairs(activecontestants) do
		if bloxxeractive then
			if #activecontestants <= 1 then
				roundresult = "BloxxerWins"
				guiprompter:FireClient(player, "Result", roundresult)
			else
				roundresult = "PlayersWin"
				guiprompter:FireClient(player, "Result", roundresult)
			end
		else
			roundresult = "PlayersWin"
			guiprompter:FireClient(player, "Result", roundresult)
		end
	end
	wait(4)
	textupdate.Value = "Showing results..."
	--teleport players back to lobby
	for _, player in pairs(activecontestants) do
		if player and player.Character then
			local humanoid = player.Character:FindFirstChild("Humanoid")
			if humanoid then
				humanoid:UnequipTools()
				player.Backpack:ClearAllChildren()
				humanoid.Health = 100
				player:FindFirstChild("PlayerGui").TextGui.Enabled = true
				player:FindFirstChild("PlayerGui").ShopGui.Enabled = true
				player:FindFirstChild("PlayerGui").SpectateGui.Enabled = true
				local lobbyspawns = workspace:WaitForChild("Lobby"):WaitForChild("Spawns"):GetChildren()
				player.Character:MoveTo(lobbyspawns[math.random(1, #lobbyspawns)].Position)
			end
		end
	end
	wait(2)
	--give results and rewards
	for _, player in pairs(players:GetPlayers()) do
		if roundresult == "BloxxerWins" then
			guiprompter:FireAllClients("LobbyResult", roundresult)
			if player == bloxxer then
				rewardplayer(player, 8, 1)
			else
				rewardplayer(player, 2, 0)
			end
		else
			guiprompter:FireAllClients("LobbyResult", roundresult)
			if player == bloxxer then
				rewardplayer(player, 2, 0)
			elseif player == sheriff then
				rewardplayer(player, 6, 1)
			else
				rewardplayer(player, 4, 1)
			end
		end
	end
	--clean workspace
	for _, item in pairs(workspace:GetChildren()) do
		if item.Name == "Pickup" then
			item:Destroy()
		end
	end
end

2 comments

0

I don't think it's a good idea to post your entire script to us random scripters.

0

handleSheriff will not be called because during placing players, and choosing roles is that no one dies ..