I have been trying to create a script where if the key V is pressed a part spawns on the humanoid leg and makes him trip, but I can't get that to work using Instance.new
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
Mouse.KeyDown:Connect(function(Key)
Key = Key:lower()
if Key == 'v' then
local part = Instance.new("Part")
part.Name = "Test"
part.Anchored = true
part.Position = Vector3.new(10,15,0)
part.Parent = game.Workspace
part.CFrame = CFrame.new(Player.Character.UpperTorso.Position.x,Player.Character.UpperTorso.Position.y- 3,Player.Character.UpperTorso.Position.z)
part.Transparency = 1
part.Size = Vector3.new(5,0,5)
part.CanCollide = true
end
end)
script.Parent = workspace.Test
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
hit.Parent.Humanoid.Sit = true
end
end)
I get the error message " Test is not a valid member of Workspace " even before pressing the key V

3 comments
use user input service not mouse.key down
is test a part of the workspace?
Part is supossed to be generated after I press the key V