"Part" is not a valid member of Workspace "Workspace" / Infinite Wield Possible on "Part", How to fix?

This is a localscript in StarterGui, I have 3 parts, each part triggers an event for a stopwatch. These parts will not load in no matter what I do.

I have tried this, (“Part” is not a valid member of Workspace “Workspace”)

handlePartTouch(game:WaitForChild("Workspace").Start, startTimer)
handlePartTouch(game:WaitForChild("Workspace").Stop, stopTimer)
handlePartTouch(game:WaitForChild("Workspace").Reset, resetTimer)

I have tried this, (Infinite Wield Possible on “Part”)

handlePartTouch(game.Workspace:WaitForChild("Start"), startTimer)
handlePartTouch(game.Workspace:WaitForChild("Stop"), stopTimer)
handlePartTouch(game.Workspace:WaitForChild("Reset"), resetTimer)

I have just tried plain this, (“Part” is not a valid member of Workspace “Workspace”)

handlePartTouch(game.Workspace.Start, startTimer)
handlePartTouch(game.Workspace.Stop, stopTimer)
handlePartTouch(game.Workspace.Reset, resetTimer)

It either works, one of them doesn’t work, two of them don’t work, or literally all of them don’t work. This only happens to the first player that joins too. So I’m at a loss on how it can be loaded for every player.

Help is appreciated!

Share whole script, not bits of it. It will help debug.

Are you using streaming enabled? If so, it won’t be able to access them until the player is in the area.
You can try using a yielding loop to wait for all of them, e.g.

local Required = {"Start", "Stop", "Reset"}
local AllFound = false
while not AllFound do
    AllFound = true
    for _, item in ipairs(Required) do
        if not game.Workspace:FindFirstChild(item) then
            AllFound = false
        end
    end
    task.wait(0.4)
end

-- other code here
1 Like
-- References to GUI elements
local frame = script.Parent.Stopwatch
local timeLabel = frame.TimeLabel

-- Variables for time tracking
local isRunning = false
local startTime = 0
local elapsedTime = 0
local timer

-- Function to update the time display
local function updateTimeDisplay()
	local totalMilliseconds = math.floor(elapsedTime * 1000)
	local hours = math.floor(totalMilliseconds / 3600000)
	local minutes = math.floor((totalMilliseconds % 3600000) / 60000)
	local seconds = math.floor((totalMilliseconds % 60000) / 1000)
	local milliseconds = totalMilliseconds % 1000
	timeLabel.Text = string.format("%02d:%02d:%02d.%03d", hours, minutes, seconds, milliseconds)
end

-- Get the LocalPlayer
local player = game.Players.LocalPlayer

-- Store original WalkSpeed and JumpPower
local originalWalkSpeed
local originalJumpPower

-- Function to set the character's movement
local function setCharacterMovement(character, walkSpeed, jumpPower)
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = walkSpeed
		humanoid.JumpPower = jumpPower
	end
end

-- Function to freeze the character
local function freezeCharacter(character)
	if character and not originalWalkSpeed then
		local humanoid = character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			originalWalkSpeed = humanoid.WalkSpeed
			originalJumpPower = humanoid.JumpPower
			setCharacterMovement(character, 0, 0)
		end
	end
end

-- Function to unfreeze the character
local function unfreezeCharacter(character)
	if character and originalWalkSpeed and originalJumpPower then
		setCharacterMovement(character, originalWalkSpeed, originalJumpPower)
		originalWalkSpeed, originalJumpPower = nil, nil
	end
end

-- Function to start the timer
local function startTimer(character)
	if not isRunning then
		isRunning = true
		freezeCharacter(character)
		task.wait(2)
		unfreezeCharacter(character)
		startTime = tick() - elapsedTime
		timer = game:GetService("RunService").RenderStepped:Connect(function()
			elapsedTime = tick() - startTime
			updateTimeDisplay()
		end)
	end
end

-- Function to stop the timer
local function stopTimer()
	if isRunning then
		isRunning = false
		timer:Disconnect()
	end
end

-- Function to reset the timer
local function resetTimer()
	stopTimer()
	elapsedTime = 0
	updateTimeDisplay()
end

-- Function to handle part touches
local function handlePartTouch(part, action)
	part.Touched:Connect(function(hit)
		local hitPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
		if hitPlayer == player then
			action(player.Character)
		end
	end)
end

-- Connect the start, stop, and reset events to touch events
handlePartTouch(game.Workspace.Start, startTimer)
handlePartTouch(game.Workspace.Stop, stopTimer)
handlePartTouch(game.Workspace.Reset, resetTimer)

-- Initialize display
updateTimeDisplay()

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