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

I cant get to weld a part in players body, It just stays in map any ideas?

Im trying to weld a part on the character so that i can make a script that kills other players that come close but I cant get it to work. This is the script im using :

local charAdded = function(char)    
local a = script:WaitForChild('hitbox'):Clone()     
local w = Instance.new('Motor6D')     
w.Part0 = char:WaitForChild('UpperTorso')     
w.Part1 = a     
w.Parent = char['UpperTorso']     
a.Parent = char 
end  game:GetService('Players').PlayerAdded:Connect(function(plr)     
if plr.Character then         
charAdded(plr.Character)     
end      
plr.CharacterAdded:Connect(charAdded) 
end) 

I put the part named "hitbox" inside the script thus having the script being the parent of 'hitbox' but the "hitbox" still just stays on the map. notes:my character is r15 the game settings avatar type is r15 This is what happens............ This is kind of what i want:..........
THE hitbox part Doesnt Stick to the player I want it to move along with the character but it wont

1 answer

I hope this is the answer you were looking for:

script.Parent = game.ServerScriptService
game.Players.PlayerAdded:Connect(function(plr) -- Checks for new players
	local Character = plr.Character -- Gets their avatar
	local ClonedPart = script.Part:Clone() -- Store the part inside the script
	ClonedPart.Parent = Character -- Stores it inside the player's character.
	
	-- After this we just need to connect the part to the character, where you want to connect is your choice, for this example I am connecting it to the head.
	local Motor6D = Instance.new("Motor6D") -- Creates a connection
	Motor6D.Parent = ClonedPart -- Stores it to the part we cloned
	Motor6D.Part0 = ClonedPart -- Joins the cloned part
	Motor6D.Part1 = Character.Head -- Joins it to the head

A quick note: You can make the part inside the script uncollidable for better performance.

After all that scripting this is will be our result.

https://drive.google.com/file/d/1hADTooiKko8eDZ6JDpiDc9eb0iPSvhSf/view?usp=sharing

*If the link doesn't work or something, kindly copy it and paste it into your browser. :)

2 comments

0

Hello thanks for your answer! In the output i get this error: 16:46:26.209 - ServerScriptService.aweld:11: attempt to index nil with 'Head' Could you send me the rblx file please?

0

Hi again i just realised that my own script works but only works with a basic square and doesnt work for example with girl, boy torso. Is there a way to fix this?

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