Ok here is my script i keep getting a error part 1 is not a valid member of workspace local part = Instance.new("Part") part.Name = "Part1" part.Parent = workspace function game.workspace.Part1(onTouch) game.Workspace.Player1.Head:remove()
end
The code you've posted will not run, so I'll try to interpret what it is supposed to mean:
local part=Instance.new("Part") part.Name="Part1" part.Parent=workspace part.Touched:connect(function() workspace:WaitForChild("Player1"):WaitForChild("Head"):Destroy() end)
It is possible that you meant to say Player1 is not a valid member of workspace and not Part1, in which case this will wait for the player (and its head) to exist before continuing.
~~~~~~~
.game.Workspace
or workspace
, you can not use both..Touched
event.You will want to use the variable 'part' you have established above, then add the .Touched event, followed by a connection into a function using :connect()
.
local part = Instance.new("Part") part.Name = "Part1" part.Parent = workspace part.Touched:connect(function() game.Workspace.Player1.Head:remove() end) --We need a end parenthesis to indicate that's the end of the function.
The :remove()
function is deprecated, it is always recommended you use a different method if one is deprecated as the code is only kept for compatibility. The recommended function to use is :Destroy()
. Also, your code will only work if there is a Player1 in the game. If you want to remove the head of anything that hits the part, you can use a variable for the Touched event. Some events will return values such as the touched event, which will return the object that hit the part.
local part = Instance.new("Part") part.Name = "Part1" part.Parent = workspace part.Touched:connect(function(hittingObject) --hittingObject will be the object that hits the part. if hittingObject.Parent:FindFirstChild('Head') then hittingObject.Parent.Head:Destroy() end end)
For line 5, your character is a model, when something hits the part, it will check that hitting part's parent to see if it has a head. Most likely for this script, it will be your arm or leg hitting the part, those are both part of the model. We take that leg or arm's parent and find the first object that is named "Head". If there is a object that is named "Head", then on line 6 the script will go to the hitting object's parent, and destroy the part in it named "Head".
Now you have basically made a kill script.