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

Help With A 'Touched' Script?

Asked by
Scootakip 299 Moderation Voter
8 years ago
function onTouch(part)
    local r = script.Parent
    r.Transparency = .5
    wait(1)
    r:remove(part)
end

script.Parent.Touched:connect(onTouch)

This script is currently working (sorta), The only problem is that I can't seem to make it so that the block only gets removed when a player touches it. I've tried a few things that result in breaking the script, so this is the version of the script that is halfway working.

Any help?

1 answer

Log in to vote
1
Answered by 8 years ago

Make a condition based off whether the object that touched it is a player or not. Try this:

local players = game:GetService("Players")
local r = script.Parent

r.Touched:connect(function(part)
    local player = part and part.Parent and players:GetPlayerFromCharacter(part.Parent)
    if player then
        r.Transparency = 0.5
        wait(1)
        r:Destroy()
    end
end)
Ad

Answer this question