Help me for my tool equip script please

Hello, please can you help me with my script, the goal is simple: 2 teams, a red team, a blue team, each team contains 4 players, a timer, once the timer has started the game begins, I I would like that when the game starts, there is an object that appears in the inventory of one of these 8 players, (only 1 person) and the goal is to pass this object to any person in order to avoid it as much as possible, before it explodes, if the object explodes on the person carrying it, the person dies.

I still tried to do something on my side. I went to see the api but there is nothing that matches my searchs.

local Players = game:GetService("Players")
local timerEnd = 20 
local timePassed = 0 
local Part1 = workspace.REDTEAM
local Part2 = workspace.BLUETEAM
local Tool = game.ServerStorage.EQUI


local function timer()
    timePassed = 0
    while true do
        task.wait(1)
        timePassed += 1
        if timePassed == timerEnd  then
            Part1.Transparency = 1
            Part2.Transparency = 1

            Part1.CanCollide = false
            Part2.CanCollide = false

            local player = Players:GetPlayerFromCharacter()
            local backpack = player.Backpack
            Tool:Clone().Parent = backpack
            break
        end
    end
end

Part1.Touched:Connect(function()
    timer()
    print(timePassed)
end)
1 Like

Your Part1.Touched event is allowed to receive multiple inputs by only one player touching it, you need debounces otherwise your functions will run multiple times at the same time.
You had a previous script before which I made some modifications.

local function touchedpart(player)
	if player then
		local backpack = player:FindFirstChild("Backpack")
		if backpack then
			Tool:Clone().Parent = backpack	
		end
	end
end

local timerDebouce = false

part1.Touched:Connect(function(hit)
	if hit.Name == "HumanoidRootPart" then
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			if not timerDebouce then
				timerDebouce = true
				timer()
				print(timePassed)
				touchedpart(player)
			else
				warn("timer already running")
			end
		end
	end
end)

Thank you very much for helping me.

1 Like

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