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

OnTouched weld not working (sword attached to hand)?

title explains it

blade = script.Parent.Blade
handle = script.Parent.Handle
Greatsword = script.Parent

handle.Touched:connect(function(hit)
	if hit.Parent == 'Humanoid' then
		local player = hit.Parent.Parent
                local WeldH = Instance.new('Weld')
                WeldH.Parent = Greatsword
                WeldH.Part0 = handle
                WeldH.Part1 = player:WaitForChild('RightHand',.5)
                WeldH.C0 = CFrame.new(0,0,0)
	else
        
	end
end)

this is all inside a model(sword)

whenever i touch the handle it doesn't react

-No errors in output

if there are any questions or something missing just comment

1 answer

✓ Accepted answer

since hit is a part, its parent will never be a humanoid, nor will it be the string "Humanoid". And hit.Parent.Parent will not be a character. Try this:

blade = script.Parent.Blade
handle = script.Parent.Handle
Greatsword = script.Parent

handle.Touched:connect(function(hit)
	--should use variable "char" for character, not player
	local char = hit.Parent --assumption
	if char:FindFirstChild('Humanoid') then --probably a character
		local player = game.Players:GetPlayerFromCharacter(char)
		if player then --making sure
			local WeldH = Instance.new('Weld')
			WeldH.Parent = Greatsword
			WeldH.Part0 = handle
			WeldH.Part1 = char:WaitForChild('RightHand',.5)
			WeldH.C0 = CFrame.new(0,0,0)
		end
	end
end)

1 comment

0

thank you!

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