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

What is wrong with this script?

Here is the script I made.. I don't know why it doesn't work:

Brick = script.Parent
AnotherBrick = game.Workspace.TP
 
if game.Workspace.Screen.Brickcolor.Name == "Bright green"
	then 
	Brick.Touched:connect(function(part)
    if part.Parent.Humanoid then -- *
        if part.Parent.Humanoid.Health > 0 then
            part.Parent:MoveTo(AnotherBrick.Position)
        end
    end
end)

3 comments

0

Mind putting it in code block?

0

Oh, sorry, sure

0

Okay, it's in code block

1 answer

There is a end missing and it's BrickColor, with capital c. So it would be like this:

Brick = script.Parent
AnotherBrick = game.Workspace.TP

if game.Workspace.Screen.BrickColor.Name == "Bright green" then
	Brick.Touched:connect(function(part)
		if part.Parent.Humanoid then
			if part.Parent.Humanoid.Health > 0 then
				part.Parent:MoveTo(AnotherBrick.Position)
			end
		end
	end)
end

A hint: use http://wiki.roblox.com/index.php?title=Output, it's really useful to find out what is wrong in your code. Run the script and check output to see if nothing is wrong.

Edit:

Ok, I tried it in studio and worked perfectly. Just changed a line here to make more sense:

Brick = script.Parent
AnotherBrick = game.Workspace.TP

Brick.Touched:connect(function(part)
	if game.Workspace.Screen.BrickColor.Name == "Bright green" then -- more useful inside the function
		if part.Parent:FindFirstChild("Humanoid") then -- this will look after humanoid, if the part isn't a character part, it won't break the script
			if part.Parent.Humanoid.Health > 0 then
				part.Parent:MoveTo(AnotherBrick.Position)
			end
		end
	end
end)

6 comments

0

Maybe the if statement about Humanoid have problems, but check out output first.

0

I got this in the output (didn't work): Attempt to connect failed: Passed value is not a function

0

Weird. What line?

0

Not sure.. how do I tell?

0

isn't it written in there? like "Script 'Workspace.Script', Line 1"

0

I can't find it.. :P

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