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

Why when the hitbox hits the player, the player dosent die?

So im making a game with alvin blox's hide n seek tutorial, and there is a problem that dosent show up in the output and im confused. there is also another problem too, when everyone teleports to the map, the seeker dosent wait in the lobby and teleports the same time the hider teleports.

Someone help me please

Script:

-- Services
local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")

local status = replicatedStorage.Values.Status

local timer = replicatedStorage.Values.Timer

local playersLeft = replicatedStorage.Values.PlayersLeft

local hitbox = serverStorage:WaitForChild("Hitbox")
-- Configs
local playersToStart = 1

local contestants = {}

-- Functions

local function chooseSeeker(availablePlayers)
	return availablePlayers[math.random(1,#availablePlayers)]
end

local function teleportPlayers(availablePlayers,spawns) -- availablePlayers: Table / spawns: Table
	for _, plr in pairs(availablePlayers) do
		if plr.Character then
			if plr.Character:FindFirstChild("HumanoidRootPart") then
				plr.Character.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,5,0)
			end
		end
	end
end

local function toMS(s)
	return ("i:i"):format(s/60%60, s%60)
end

local function addHitbox(player)
	
	if player then
		if player.Character then
			local character = player.Character
			local hitboxClone = hitbox:Clone()
			hitboxClone.CFrame = character.HumanoidRootPart.CFrame
			local weld = Instance.new("Weld")
			weld.Part0 = character.HumanoidRootPart
			weld.Part1 = hitboxClone
			weld.Parent = hitboxClone
			hitboxClone.Parent = character
			print("hitbox added for "..player.Name)
			
			return hitboxClone
		end
	end
end

local function isContestant(plr)
	for _, contestant in pairs(contestants) do
		if contestants == plr then
			return true
		end
	end
	
	return false
end

local function kickOutContestant(plr)
	for i, contestant in pairs(contestants) do
		if contestants == plr then
			table.remove(contestants,i)
			print("Booted "..contestant.Name.." from the game")
		end
	end
end

while wait(1) do
	
	Contestants = {}
	
	repeat
		
		print("Not enough players in-game")
		status.Value = playersToStart.." players needed to start ("..#game.Players:GetPlayers().."/"..playersToStart..")"
		
		wait(1)
		
	until #game.Players:GetPlayers() >= playersToStart
	
	for i = 5,0,-1 do
		status.Value = "Next round starts in "..i.." seconds"
		wait(1)
	end
	
    contestants = game.Players:GetPlayers()
	
	local seeker = chooseSeeker(contestants)
	
	status.Value = "The chosen seeker is..."
	wait(1)
	status.Value = seeker.Name.."!"
	
	wait(3)
	
	local map = game.Workspace.TempMap
	
	kickOutContestant(seeker)
	
	teleportPlayers(contestants,map.Spawns:GetChildren())

	local hitbox = addHitbox(seeker)
	-- disconnect me
	seekerhitBoxConnection = hitbox.Touched:Connect(function(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then -- real player
			print(player.Name)
			    if isContestant(player) then
				print("Real contestant")
				kickOutContestant(player)
				status.Value = player.Name.." was killed by the Seeker"
				if player.Character then
					player.Character.Torso:Destroy()
				end
				print("Kicked")
			end
		end
	end)
	
	status.Value = "Get ready to hide!"
	
	wait(3)
	
	for i = 45,0,-1 do
		status.Value = "Go Hide"
		timer.Value = toMS(i)
		playersLeft.Value = #contestants
		wait(1)
	end
	
	teleportPlayers({seeker},map.SeekerSpawns:GetChildren())
	
	status.Value = "The Seeker Has Been Released"
	
	if seeker.Character then
		seeker.Character.Humanoid.WalkSpeed = 50
	end
	
	wait(3)
	
	local outcome = nil
	
		for i = 300,0,-1 do
		status.Value = "Game In Progress"
		timer.Value = toMS(i)
		playersLeft.Value = #contestants
		
		if #contestants == 0 then
			outcome = "SeekerWon"
			break
		end
		
		wait(1)
	end
	
	if outcome == "SeekerWon" then
		status.Value = "The Seeker Wins!"
	else
		status.Value = "Time's Up! Contestants Win!"
	end
	
	status.Value = "End of Round"
	
	if seekerhitBoxConnection then seekerhitBoxConnection:Disconnect() print("Successfully disconnected") end
	
	wait(2)
end

2 answers

Sometimes a player will not have a Torso they will have an UpperTorso try destroying the hit.Parent:FindFirstChild("Head") instead.

2 comments

0

But in which line do i put it?

0

Line 120.

If your character is in R15, then you need a UpperTorso, instead of a Torso. Destroy that. Here's the fixed script.

-- Services
local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")

local status = replicatedStorage.Values.Status

local timer = replicatedStorage.Values.Timer

local playersLeft = replicatedStorage.Values.PlayersLeft

local hitbox = serverStorage:WaitForChild("Hitbox")
-- Configs
local playersToStart = 1

local contestants = {}

-- Functions

local function chooseSeeker(availablePlayers)
    return availablePlayers[math.random(1,#availablePlayers)]
end

local function teleportPlayers(availablePlayers,spawns) -- availablePlayers: Table / spawns: Table
    for _, plr in pairs(availablePlayers) do
        if plr.Character then
            if plr.Character:FindFirstChild("HumanoidRootPart") then
                plr.Character.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,5,0)
            end
        end
    end
end

local function toMS(s)
    return ("i:i"):format(s/60%60, s%60)
end

local function addHitbox(player)

    if player then
        if player.Character then
            local character = player.Character
            local hitboxClone = hitbox:Clone()
            hitboxClone.CFrame = character.HumanoidRootPart.CFrame
            local weld = Instance.new("Weld")
            weld.Part0 = character.HumanoidRootPart
            weld.Part1 = hitboxClone
            weld.Parent = hitboxClone
            hitboxClone.Parent = character
            print("hitbox added for "..player.Name)

            return hitboxClone
        end
    end
end

local function isContestant(plr)
    for _, contestant in pairs(contestants) do
        if contestants == plr then
            return true
        end
    end

    return false
end

local function kickOutContestant(plr)
    for i, contestant in pairs(contestants) do
        if contestants == plr then
            table.remove(contestants,i)
            print("Booted "..contestant.Name.." from the game")
        end
    end
end

while wait(1) do

    Contestants = {}

    repeat

        print("Not enough players in-game")
        status.Value = playersToStart.." players needed to start ("..#game.Players:GetPlayers().."/"..playersToStart..")"

        wait(1)

    until #game.Players:GetPlayers() >= playersToStart

    for i = 5,0,-1 do
        status.Value = "Next round starts in "..i.." seconds"
        wait(1)
    end

    contestants = game.Players:GetPlayers()

    local seeker = chooseSeeker(contestants)

    status.Value = "The chosen seeker is..."
    wait(1)
    status.Value = seeker.Name.."!"

    wait(3)

    local map = game.Workspace.TempMap

    kickOutContestant(seeker)

    teleportPlayers(contestants,map.Spawns:GetChildren())

    local hitbox = addHitbox(seeker)
    -- disconnect me
    seekerhitBoxConnection = hitbox.Touched:Connect(function(hit)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then -- real player
            print(player.Name)
                if isContestant(player) then
                print("Real contestant")
                kickOutContestant(player)
                status.Value = player.Name.." was killed by the Seeker"
                if player.Character then
                    player.Character.UpperTorso:Destroy()
                end
                print("Kicked")
            end
        end
    end)

    status.Value = "Get ready to hide!"

    wait(3)

    for i = 45,0,-1 do
        status.Value = "Go Hide"
        timer.Value = toMS(i)
        playersLeft.Value = #contestants
        wait(1)
    end

    teleportPlayers({seeker},map.SeekerSpawns:GetChildren())

    status.Value = "The Seeker Has Been Released"

    if seeker.Character then
        seeker.Character.Humanoid.WalkSpeed = 50
    end

    wait(3)

    local outcome = nil

        for i = 300,0,-1 do
        status.Value = "Game In Progress"
        timer.Value = toMS(i)
        playersLeft.Value = #contestants

        if #contestants == 0 then
            outcome = "SeekerWon"
            break
        end

        wait(1)
    end

    if outcome == "SeekerWon" then
        status.Value = "The Seeker Wins!"
    else
        status.Value = "Time's Up! Contestants Win!"
    end

    status.Value = "End of Round"

    if seekerhitBoxConnection then seekerhitBoxConnection:Disconnect() print("Successfully disconnected") end

    wait(2)
end

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