Detecting click input without a tool
To be able to detect clicking inputs without a tool, I suggest you use UserInputService.
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gpe)
if gpe == false then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("left mouse clicked!")
end
end
end)
I won't go too in-depth about UserInputService as it is not your main question, you can check the wiki for more information here.
UIS.InputBegan is an event that fires whenever you send an input (like mouse clicks, keyboard button presses, etc), and it passes two arguments, an InputObject instance called input and a bool value called gameProcessedEvent.
The input argument contains Enum values that represent the information of the your input, such as UserInputType and UserInputState.
The gameProcessedEvent argument represents whether or not something got fired with the input.
For example, if the input is a click, and a button or something was pressed with the same input, gameProcessedEvent would be true. otherwise, it would be false.
Grabbing people
Now your main question. What you want to do is sort of "attach" the RootPart of another character to your character's RootPart, making it look like you've grabbed them.
There are quite a few instances that allow you to attach a Part to another Part, but in this case you'd be using Welds!
All you have to do is assign the Part0 and Part1 property, and the two parts will stick together.
To make them offset from each other, you'll be assigning the C0 and C1 properties.
Let's say we have both you and your opponent's RootParts defined as variables: rootPart and enemyRootPart.
local weld = Instance.new("Weld")
weld.Part0 = rootPart
weld.Part1 = enemyRootPart
weld.C0 = CFrame.new(0, 0, -1)
weld.Parent = rootPart
Putting them together
Now we know how to weld the RootParts. To actually make this execute only when you've clicked, we're going to use Remotes.
Remotes will allow communicate between the client (a player) and the server.
Since user input (like clicking) can only be detected on the client (via a LocalScript), and actually applying the Welds must be done of the server (via a ServerScript) for everyone to see, we will require Remotes to connect them together.
local UIS = game:GetService("UserInputService")
local repstore = game:GetService("ReplicatedStorage")
local grabRemote = repstore:WaitForChild("GrabRemote")
UIS.InputBegan:Connect(function(input, gpe)
if gpe == false then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
grabRemote:FireServer()
end
end
end)
local repstore = game:GetService("ReplicatedStorage")
local grabRemote = repstore:WaitForChild("GrabRemote")
grabRemote.OnServerEvent:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local rootPart = char:WaitForChild("HumanoidRootPart")
local enemyChar = [insert enemy character model here]
local enemyRootPart = enemyChar:WaitForChild("HumanoidRootPart")
local weld = Instance.new("Weld")
weld.Part0 = rootPart
weld.Part1 = enemyRootPart
weld.C0 = CFrame.new(0, 0, -1)
weld.Parent = rootPart
end)
For the hitbox system, I won't cover how to do it here, but I recommend using a GetTouchingParts() method of doing hitboxes. You can find the article on it here.
Hope this helped, thanks for reading!
4 comments
Thank you so much! I'll accept the answer at the end of the day, just trying to edit all of this into my game. So far I made the remoteevent and made the animation play with no tool! That's insane! I'm pretty new to scripting so im glad I got something done from all this for now. Once again, thank you!
I've made the GetTouchingParts() detection, im able to return the table and all that, but how would I use the TouchingParts and filter out everything else but the enemy'sChar?
Loop through each part inside the table, and check if they are apart of a character model. To do this you could get the Parent of the part (part.Parent) and check if the Parent has a Humanoid in one of its children (if part.Parent:FindFirstChild("Humanoid") then).
if you have found a Humanoid, that means the "part.Parent" is the "character model" of that character. If you want the character model to be of a specific player, you can check if the character model and the opponent player's "Character" property are the same. (if part.Parent == [insert enemy player instance here].Character)