Workspace is not a valid Member of Workspace

I was doing Cuffs Script and this happens.
I think thats a funny error Lol. :joy:

Workspace is not a valid member of Workspace

Proof

image

Also, I am clicking

The cuffs script:

script.Parent.Equipped:Connect(function(mouse)
	mouse.Button1Down:connect(function()
		if mouse.Target ~= nil then
			print(mouse.Target:GetFullName())
		local plr = game.Workspace[mouse.Target.Parent.Name]
			_,plr = pcall(function() return game.Players[mouse.Target.Parent.Name] end)
			print(plr.Name)
			print(mouse.Target.Parent.Name)
			if plr ~= nil then
				local isCuffed = plr
				coroutine.wrap(function()
					local cframeTarget = plr
					while plr == cframeTarget do wait() pcall(function()
						plr.Character.Torso.Anchored,plr.Character.Torso.CFrame = true, game.Players.LocalPlayer.Character.Torso.CFrame*CFrame.new(0,0,-2.5)
						pcall(function()
							cframeTarget.Character.Torso.Anchored = false
							end)
						end)
					end
				end)
			end
		end
	end)
end)

Is there something that is causing this error, since that error was so funny.

You are pointing at the baseplate or that spawn location, and its parent is workspace. So you end up trying to find the workspace within the workspace.

Instead of reinventing the wheel by using Button1Down, use tool.Activated.

local tool = script.Parent
local Players = game:GetService("Players")
local client = Players.LocalPlayer
local cursor = client:GetMouse()

tool.Activated:Connect(function()
    local target = Players:GetPlayerFromCharacter(cursor.Target and cursor.Target.Parent)

    if target and target ~= client then
        -- target is the target player
    end 
end)

I also used :GetPlayerFromCharacter, which is more reliable.

1 Like

Don’t you mean GetMouse?
Since its not a valid member of Players, thats what the console said.

What do you mean? That is what I wrote. And I got it off the player, not the Players service.

Nvm, I did not see that.
Sorry.

Also, it says nil For some reason.

LocalPlayer is nil on the server and player:GetMouse() returns nil on the server. You need to make use of the mouse in a LocalScript, and use RemoteEvents if you need to have the server do something.