Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to shove a part inside a player so that i detect when it touches someone???

How to have an invisible part inside the players? Do i put it in a specific category like starter pack or something? It needs to move along with the player like a hitbox or something

2 answers

I'm not really an expert but you could use a morph system which when a new player joins it automatically morphs them so they have a part in their chest which is invisible like a hit box or just write a script so if a humanoid is detected touching a part with another humanoid it does what you want it to do

UPDATE:

This script should work to morph it onto the player

If you put a script with the code I provided below in serverscriptservice with the part you want inside in the script it should weld it to the players uppertorso if using R15. If using R6 just simply change the UpperTorso text to the part you want

local charAdded = function(char)
	local a = script:WaitForChild('hitbox'):Clone() -- Hitbox should be changed to whatever the part name is
	local w = Instance.new('Motor6D')
	w.Part0 = char:WaitForChild('UpperTorso') -- Change this to whatever part of the character you wish to weld it to
	w.Part1 = a
	w.Parent = char['UpperTorso'] -- This should be the same part as above
	a.Parent = char
end

game:GetService('Players').PlayerAdded:Connect(function(plr)
	if plr.Character then
		charAdded(plr.Character)
	end
	
	plr.CharacterAdded:Connect(charAdded)
end)

40 comments

0

Awesome but where would i place the part with the script so that it moves with the player?

0

I'd say place it in serverscriptservice,workspace or replicated storage. I ain't sure though. I guess it depends what you want it to do when the hitbox is detected

0

Right now i have it in a part in workspace where should it actually go so that it moves with the character (Im trying so hard to make sense I hope u understand what im talking about)

0

Have you made it sort of morph to the character?

0

I dont know how to do that Ill search it

0

You using r15 or r6?

0

r15

0

I have provided a script above for you

0

Thankss ill try it!

0

What I suggest doing for the part is getting a R15 dummy and copying the uppertorso part and rename it and make it invisible for the morph and just place it in the script with a name like hitbox

0

great ill do that!

0

Alright, Let me know if it works!

0

I put this script in serverscriptservice, put the part named "hitbox" inside the the script making the parent of 'hitbox' the script and when i run it spawns in the same location that i placed it at first and doesnt move on the character

0

What am i doing wrong?

0

Let me check it out now

0

Did you anchor the part? If so unanchor it

0

If it doesn't work upload the RBXL on here and I can take a look at the script. It all works on my end unsure why it isn't working

0

Its not anchored

0

Thats the rblx. By the way thanks so much for being so helpful!!!

0

I'll check the rbxl now

0

Here. You made the part too big it worked but the part was massive. Here is a fixed version of it now https://we.tl/t-REYz88egal

0

Oh lol Thanks for being so helpful, you are amazing! 

0

Also is it supposed to not stick on the player and just stand there on the map?

0

It should move around with the player

0

Alright

0

What the hell is wrong with my character

0

What happened?

0

The part doesnt stay like that it just stays in the map

0

Hmm. Make sure you are on r15. Go to gamesettings > Avatar > Avatar Type > Make sure R15 has a blue circle. Make sure the script is in serverscriptservice

0

Its set to r15

0

I am unsure on why it isn't working. Could you send me a gif of it?

0

I have a screenshot http://pasteboard.co/Jg7NdoP.png im not on pc anymore sorry

0

I am unsure why it isn't working. Could you try remove your package and test it then?

0

Can you please explain how to do that?

0

If you go on your avatar and go to a basic block avatar. I want to see if that will work

0

It works with the basic square avatar!!! Awesome but that means it wont work for every player?

0

Is there a way to make it work for every avatar??

0

I am trying to think why it only works for the square avatar.

Yo Mast3r,

I would just use Weld Constraints to Weld the parts onto the character's body parts... That way you can have a bunch of hit boxes on different parts of the body part or even one part... For example, if you want a part to be welded to the UpperTorso and have a hitbox on there:

####Server Script in ServerScriptService: Weld Part To Torso

local part; -- Initialize this to where ever the part is, it can be anywhere as long as it's not on the client (For FE Enabled reasons)
local players = game:GetService("Players");

players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait();
	local u_torso = char:WaitForChild("UpperTorso");
	local new_weld = Instance.new("Weld Constraint");
	local new_part = part:Clone();
	new_part.Parent = u_torso;
	new_part.CFrame = u_torso.CFrame;
	new_weld.Parent = new_part;
	new_weld.Part0 = u_torso;
	new_weld.Part1 = new_part;
end)

###That would weld the part to the character's upper torso and then you can detect collision with that part. Remember that my script places the part in the UpperTorso, so normal character detection won't work because the parent of the part isn't the character but instead the UpperTorso... You can change the parent if you want, this was just an illustration of WeldConstraints.

##Hope I helped and have a wonderful day/night.

Thanks,

Best regards,

Idealist Developers

5 comments

0

I put this script in serverscriptservice, put the part named "hitbox" inside the the script making the parent of 'hitbox' the script and when i run it spawns in the same location that i placed it at first and doesnt move on the character what am i doing wrong?

0

Did you correctly initialize the part variable in the script to reference the "hitbox" part?

0

I got it to work but it only works with the default avatar the square one Could you help me understand why that happens??

0

It will only work with R15 avatars because I am referencing "UpperTorso" For R6 you need to reference "Torso" instead. However, if you want it to work with both, you can use the HumanoidRootPart and reference that instead. Then you can mess around with the CFrame based on where you want the part to be.

0

ok thank you ill try that

This discussion is preserved as it was. New answers, comments, and votes are closed.