Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with OnTouched script? (EDITED)

Asked by
Xl5Xl5 65
8 years ago

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)


0
Can you elaborate on what you want? Re-word it please. Goulstem 8144 — 8y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

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)
0
thank you! :D Xl5Xl5 65 — 8y
Ad

Answer this question