Player = game:GetService('Players').LocalPlayer mouse = Player:GetMouse() function onKeyDown(key) key = key:lower() if key == "z" then print("Success") Instance.new("Part") game.Workspace.Part.Parent = workspace game.Workspace.Part.CFrame = CFrame.new(10.184, 2.5, -20.017) game.Workspace.Part.Name = "Brick1" end end mouse.KeyDown:connect(onKeyDown)
This script is supposed to create a new part when I press Z (And rename the Part "Brick1"
but it returns with the output Part is not a valid member of Workspace
AND I DONT KNOW WHY
You wrote Instance.new("Part")
on line 8 and didn't set its parent, so it isn't in workspace. You're trying to get it from workspace on line 9 so you can set its parent to workspace, which it isn't in.
solution:
Player = game:GetService('Players').LocalPlayer mouse = Player:GetMouse() function onKeyDown(key) key = key:lower() if key == "z" then print("Success") local part = Instance.new("Part", workspace) part.CFrame = CFrame.new(10.184, 2.5, -20.017) part.Name = "Brick1" end end mouse.KeyDown:connect(onKeyDown)