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

What is wrong with my onTouched and Velocity Script?

What's wrong with my tire destruction script? I'm making a script where if a certain part (TireBreaker) hits a tire (BRTire) at a magnitude of 10, then those 5 activities under line 4 will occur. I've tested it and it does not seem to work. What am I missing?

function OnTouched(Part)
if Part.Name == 'TireBreaker' then
	local mag = Part.Velocity.Magnitude
	if mag > 10 then
		script.Parent.TireDirt.Transparency = 0
		script.Parent.BR1.Enabled = true
		script.Parent.BR2.Enabled = true
		script.Parent.BR3.Enabled = true
		script.Parent.Parent.BRB.CanCollide = true
	
end

end
end

5 comments

0

Did you Connect your function to a Touched event?

0

Add prints, and make sure the script is not Disabled.

0

I added prints and I am getting nothing. The script is not disabled.

0

Did you eve listen what did incapaz said? Did you connected function to a Touched event? EXAMPLE: script.Parent.Touched:Connect(onTouched) at the end of script.

0

Oh I totally forgot about that. I did this: [ script.Parent.Touched:Connect(function(otherPart) end) ] and it still does not work. What am I doing wrong?

1 answer

✓ Accepted answer

I think this should work not sure but I think it should work. If it works great! Didn't test this.

script.Parent.Touched:Connect(function(hit)
	if hit.Name == "TireBreaker" then
		local mag = script.Parent.Magnitude
		if mag > 10 then
			script.Parent.TireDirt.Transparency = 0
			script.Parent.BR1.Enabled = true
			script.Parent.BR2.Enabled = true
			script.Parent.BR3.Enabled = true
			script.Parent.Parent.BRB.CanCollide = true
		end
	end
end)

2 comments

0

"Magnitude is not a valid member of MeshPart" it says

0

Duh, forgot velocity, my bad. Thanks so much dude.

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