wait(3)
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local toolEquipped = true
local character = script.Parent
local timeValue = game.ReplicatedStorage:WaitForChild("Timer")
function Format(Int)
return string.format("%02i", Int)
end
function convertToHMS(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
return Format(Minutes)..":"..Format(Seconds)
end
tool.Equipped:Connect(function()
character = tool.Parent
end)
timeValue.Changed:connect(function()
local seconds = timeValue.Value
if seconds > 15 then
script.Parent.Frame.Screen.SurfaceGui.TimerText.Text = convertToHMS(seconds)
script.Parent.Frame.Screen.SurfaceGui.TimerText.TextColor3 = Color3.fromRGB(255, 255, 255)
toolEquipped = true
else
if toolEquipped then
if character then
if not character:FindFirstChildWhichIsA("Tool") then
toolEquipped = false
character.Humanoid:EquipTool(tool)
end
end
end
script.Parent.Frame.Screen.SurfaceGui.TimerText.Text = convertToHMS(seconds)
script.Parent.Frame.Screen.SurfaceGui.TimerText.TextColor3 = Color3.fromRGB(255, 0, 0)
tool.Handle.Tick:Play()
end
if seconds == 1 then
wait(1)
tool.Handle.Tick:Stop()
tool.Handle.Beep:Play()
end
end)
wait(3)
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local toolEquipped = true
local character = script.Parent
local timeValue = game.ReplicatedStorage:WaitForChild("Timer")
function Format(Int)
return string.format("%02i", Int)
end
function convertToHMS(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
return Format(Minutes)..":"..Format(Seconds)
end
tool.Equipped:Connect(function()
character = tool.Parent
end)
timeValue.Changed:connect(function(player)
local seconds = timeValue.Value
if seconds > 15 then
script.Parent.Frame.Screen.SurfaceGui.TimerText.Text = convertToHMS(seconds)
script.Parent.Frame.Screen.SurfaceGui.TimerText.TextColor3 = Color3.fromRGB(255, 255, 255)
toolEquipped = true
else
if toolEquipped then
if character then
if not character:FindFirstChildWhichIsA("Tool") then
toolEquipped = false
character.Humanoid:EquipTool(tool)
end
end
end
script.Parent.Frame.Screen.SurfaceGui.TimerText.Text = convertToHMS(seconds)
script.Parent.Frame.Screen.SurfaceGui.TimerText.TextColor3 = Color3.fromRGB(255, 0, 0)
tool.Handle.Tick:Play()
end
if seconds == 1 then
wait(1)
tool.Handle.Tick:Stop()
tool.Handle.Beep:Play()
end
end)
i might know whatâs the issue. You made a variable local character = script.Parent, although you said local tool = script.Parent. So I think you should do local character = tool.Parent instead, or just leave it empty because youâve already made a statement in a function.
Iâd rather just leave this blank, so that your timeValue.Changed event doesnât detect if thereâs a character variable or not and itâll only activate when the Tool gets Equipped
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local toolEquipped = true
local character
local timeValue = game.ReplicatedStorage:WaitForChild("Timer")
function Format(Int)
return string.format("%02i", Int)
end
function convertToHMS(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
return Format(Minutes)..":"..Format(Seconds)
end
tool.Equipped:Connect(function()
character = tool.Parent
end)
timeValue.Changed:connect(function()
local seconds = timeValue.Value
if seconds > 15 then
script.Parent.Frame.Screen.SurfaceGui.TimerText.Text = convertToHMS(seconds)
script.Parent.Frame.Screen.SurfaceGui.TimerText.TextColor3 = Color3.fromRGB(255, 255, 255)
toolEquipped = true
else
if toolEquipped then
if character then
if not character:FindFirstChildWhichIsA("Tool") then
toolEquipped = false
character.Humanoid:EquipTool(tool)
end
end
end
script.Parent.Frame.Screen.SurfaceGui.TimerText.Text = convertToHMS(seconds)
script.Parent.Frame.Screen.SurfaceGui.TimerText.TextColor3 = Color3.fromRGB(255, 0, 0)
tool.Handle.Tick:Play()
end
if seconds == 1 then
wait(1)
tool.Handle.Tick:Stop()
tool.Handle.Beep:Play()
end
end)
Infinite yield possible on âPlayers.Tunnells.Backpack.Watch:WaitForChild(âHumanoidâ)â - Studio
also i want the tool to equip itself when its >15
Where exactly is that warning occurring? Also you could just reference the Character using tool.Parent.Parent, since by default itâll be parented to the Playerâs Backpack when you start the game
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local toolEquipped = true
local player = script.Parent.Parent
local character
local timeValue = game.ReplicatedStorage:WaitForChild("Timer")
function Format(Int)
return string.format("%02i", Int)
end
function convertToHMS(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
return Format(Minutes)..":"..Format(Seconds)
end
tool.Equipped:Connect(function()
character = tool.Parent
end)
tool.Unequipped:Connect(function()
character = player.Character
end)
timeValue.Changed:connect(function()
local seconds = timeValue.Value
if seconds > 15 then
script.Parent.Frame.Screen.SurfaceGui.TimerText.Text = convertToHMS(seconds)
script.Parent.Frame.Screen.SurfaceGui.TimerText.TextColor3 = Color3.fromRGB(255, 255, 255)
toolEquipped = true
else
if toolEquipped then
if character then
if not character:FindFirstChildWhichIsA("Tool") then
toolEquipped = false
character.Humanoid:EquipTool(tool)
end
end
end
script.Parent.Frame.Screen.SurfaceGui.TimerText.Text = convertToHMS(seconds)
script.Parent.Frame.Screen.SurfaceGui.TimerText.TextColor3 = Color3.fromRGB(255, 0, 0)
tool.Handle.Tick:Play()
end
if seconds == 1 then
wait(1)
tool.Handle.Tick:Stop()
tool.Handle.Beep:Play()
end
end)