Player is not a valid member of Workspace "Workspace"

Hi Everyone!

I’m trying to clone a shovel (its just a single part) from server storage done on a serverscript in serverscriptservice, and parent it to the player in workspace (example game.Workspace.Player01) however I get some error. Any help is appreciated thanks!

Code:

game.Players.PlayerAdded:Connect(function(player)
	local shovel = game.ServerStorage.ShovelStorage.DefaultShovel:Clone()
	shovel.Name = "DefaultShovel"
	shovel.Parent = game.Workspace[player.Name]
	shovel.Orientation = shovel.Orientation + Vector3.new(-90,0,0)

	while wait() do
		shovel.CFrame = game.Workspace[player.Name].RightHand.CFrame + Vector3.new(0,0,-1)
	end
end)

-- Error: MasterWindowz7And10 is not a valid member of Workspace "Workspace"

Change

shovel.Parent = game.Workspace[player.Name]

to

shovel.Parent = player.Character
1 Like

That stops the errors (ty!), but now the shovel is not cloning into my player anymore…

Yea my bad, just use this instead

game.Players.PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function(char)

	local shovel = game.ServerStorage.ShovelStorage.DefaultShovel:Clone()
	shovel.Name = "DefaultShovel"
	shovel.Parent = char
	shovel.Orientation = shovel.Orientation + Vector3.new(-90,0,0)

	while wait() do
		shovel.CFrame = char:WaitForChild('RightHand').CFrame * CFrame.new(0,0,-1)
	end
  end)
end)

so you get a shovel everytime the character spawns

1 Like