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

ontouched change color???

Asked by 10 years ago

hello can you know how to make a script so as i touch a brick it turns to another color? P.S need it for my new game in progress,Malware invasion. and also i need to do a lift like in flood escape... you know...... making the game on rounds. The point of the game is to get rid of the malwares comes in the city: viruses,worms,trojans. i want to do those scripts: when viruses touch you,makes you do spam messages without doing anything.... when worms touch you, removes your arms,legs,body,and head and hen you die.... trojans hit you with lightings that kill ya..... answer just script pro's...... umm,and when you touch the brick to change the color, viruses,worms.trojans dissapear.... do you know how to do that? remember,script pro's answear thiss.... ???????????

3 answers

Log in to vote
0
Answered by 10 years ago

Well, let's assume that the brick is the scripts parent. From this we can create a Touched event that will check when a player has touched the brick. From this we can then go onto changing the colour of the brick using BrickColor.random() and then we can create a Table of a list of items in Workspace you want removing. We could then go on to do a For Loop across Workspace and if the name matches, then the script removes it. Next we need to make sure we have a debounce so that the touched event doesn't occur twice simultaneously. So the final script ends up like this:

local Brick = script.Parent --The Brick
local Debounce = false --Debounce for safety
local BadThings = { --List of things you want removing
    ["virus"] = true;
    ["worm"] = true;
    ["trojan"] = true;
}

Brick.Touched:connect(function(Hit) --Detects brick being touched
    if Debounce == false then
        Debounce = true
        local Hum = Hit.Parent:findFirstChild("Humanoid")
        if Hum then --Checking that what touched it is a Player
            Brick.BrickColor = BrickColor.random() --Random BrickColor
            for _,v in next Workspace:GetChildren() do --For loop
                if BadThings[v.Name:lower()] ~= nil then --Checking names.
                    v:Destroy() --Destroying them
                end
            end
        end
        Debounce = false
    end
end)
Ad
Log in to vote
0
Answered by 8 years ago

it's easy,

function onTouch(Player)--no other brick can activate it, only the player.
    wait(0.2)
    game.Workspace.Part.BrickColor = BrickColor.Random()
end
script.Parent.Touched:connect(onTouch)

it was tested.

Log in to vote
-1
Answered by 10 years ago

went touched it, wat color you want .

Answer this question