so im trying to make a hitbox for a bite tool and in the 9th line (right before the "end)") it does not send the part to my character, giving me the error shown in the title
script.Parent.Activated:Connect(function(player) local hitbox = Instance.new("Part",game.Workspace) hitbox.Name = "Hitbox" hitbox.Anchored = true hitbox.CanCollide = false hitbox.BrickColor = BrickColor.new("Really red") hitbox.Transparency = 0 hitbox.Size = Vector3.new(5,5,5) hitbox.CFrame = CFrame.new[player.Character.Torso.CFrame] end)
The tool.Activated
event does not pass a player
who activated the tool to your listener. Thus, player
is nil
.
If this is in a local script, you can use Players.LocalPlayer
```lua local client = game:GetService("Players").LocalPlayer; local hitbox = Instance.new("Part"); --// second parent argument is deprecated and causes performance issues if misused, parent object always last
--// assign other props here
hitbox.CFrame = CFrame.new(client.Character.HumanoidRootPart.Position); hitbox.Parent = game.Workspace; ```
Another issue you have is you are indexing the new
function itself and not calling it. And you cannot construct a CFrame
out of a CFrame
. You can, out of a Vector3
and numbers however.
CFrame.new(client.Character.HumanoidRootPart.Position);
Also R15 does not have a Torso
but all body types have a HumanoidRootPart
. Use that for compatibility purposes.
If this is in a server
script, you can use tool.Parent
to get the character when the tool is equipped.
here is an example;
```lua local tool = script.Parent;
tool.Activated:Connect(function()
local character = tool.Parent; --// This tool is going to be activated when equipped so this will be the character. --// Create your part down here
end); ```