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

Help With A 'Touched' Script?

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

✓ Accepted answer

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)

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