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

idk why this script wont work its not disabled, trying to make some thing diaper how do i fix?

the script is not disabled

local tri = "asd"
function onTouch(part) 
	local humanoid = part.Parent:FindFirstChild("Humanoid") 
	if (humanoid ~= nil) then	-- if a humanoid exists, then
		--humanoid.Health = 0	-- damage the humanoid
	end 
	if humanoid then
		tri = false
	else
		tri = true
	end
	
	if tri == true then
	part.Transparency = 1
		part.CanCollide = false
	end
	
	wait(3)
	part.Transparency = 0
		part.CanCollide = true
		
		
end



	
script.Parent.Touched:connect(onTouch)

2 comments

0

the humanoid health = 0 part is also a comment. (in line 05)

0

what r u trying to do exactly?

1 answer

✓ Accepted answer

Im not 100% sure what your wanting but this is what I pieced together. (assuming you are wanting this script to affect a player when they touch the part)

local tri = nil
function onTouch(part) 
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    if (humanoid ~= nil) then   -- if a humanoid exists, then
        --humanoid.Health = 0   -- damage the humanoid
    end 
    if humanoid then
        tri = true --switched to true
    else
        tri = false --switched to false
    end

    if tri == true then
    part.Transparency = 1
        part.CanCollide = false
    end

    wait(3)
    part.Transparency = 0
        part.CanCollide = true


end
script.Parent.Touched:connect(onTouch)

Your problem was where you set tri equal to true or false, based on what I think your wanting, you mixed the two up. As shown above I flipped the true and false and it worked(shown with comments.) The way you had it set was, if the part was NOT a player then set the transparency = 1.

Personally I would do it this way. Instead of setting a variable equal to true or false based on whether or not the part is a player and then checking that variable to detect if the part indeed was a player, you can skip setting a variable and just run the code if it detects a humanoid. The end goal is the same the code is just shorter.

local tri = nil
function onTouch(part) 
    local humanoid = part.Parent:FindFirstChild("Humanoid")  
    if humanoid then --checks if part is a player, if not do nothing
        part.Transparency = 1
        part.CanCollide = false
		wait(3)
	  	part.Transparency = 0
	    part.CanCollide = true
    end
end
script.Parent.Touched:connect(onTouch)

1 comment

0

ikr

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