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

Help with OnTouched script? (EDITED)

Okay, right so I have this script I put in to my one of my tools. It works absolutely fine, but how can I get it so that if the name is "BloodSponge" it will not effect the "Blood"?

EDIT-
Tool>Sponge>Script is here< Sponge touches hit.Name == "Blood" then it then the Blood removes itself,

function onTouch(hit)
if hit.Name == "Blood" then
hit.Transparency = 0.2
wait(0.2)
hit:Remove()

then the Sponge aka ketchup new name is "BloodSponge" and turns red.

ketchup.Name = "BloodSponge"
ketchup.BrickColor = BrickColor.new("Bright red")
end
end

script.Parent.Touched:connect(onTouch)

How can I get it so when ketchup.Name = "BloodSponge" it will not remove the "Blood"?

Full script

ketchup = script.Parent

function onTouch(hit)
if hit.Name == "Blood" then
hit.Transparency = 0.2
wait(0.2)
hit:Remove()
ketchup.Name = "BloodSponge"
ketchup.BrickColor = BrickColor.new("Bright red")
end
end

script.Parent.Touched:connect(onTouch)


1 comment

0

Can you elaborate on what you want? Re-word it please.

1 answer

✓ Accepted answer

You have to check the tool's name before wiping the blood. If it's name is just 'Sponge' then delete the blood and rename it, if the name is 'BloodSponge' then do nothing.

local ketchup = script.Parent

function onTouch(hit)
	--Check hit's name
	if hit.Name == "Blood" then
		--Check ketchup's name
		if ketchup.Name == 'Sponge' then
			--If it's name is sponge, do the stoof
			hit.Transparency = 0.2
			wait(0.2)
			hit:Destroy()
			ketchup.Name = "BloodSponge"
			ketchup.BrickColor = BrickColor.new("Bright red")
		else
			--Otherwise do nothing
			print('Sponge is saturated! Cannot wipe up blood!')
		end
	end
end

script.Parent.Touched:connect(onTouch)

1 comment

0

thank you! :D

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