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

My zombie script is not working. Hard to explain here. Help?

Okay. Im trying to make a script where once you kill a zombie, a message will appear congratulating you and also disabling another script. I tried to make a script that can do that but it didn't work, in both displaying a message and disabling the other script.

So, can you guys see if theres anything wrong with this script?

local humanoid = workspace.Zombie.Humanoid
local disaster = workspace:findFirstChild ("Disaster Script")

function win()
	print ("You Win")
end

if humanoid.health == 0 then
	print (win())
		if win() == true then
			if disaster == true then
				disaster = false
		end
	end
end	

1 answer

✓ Accepted answer

I think what you are trying to print something to the players screen, the print() function only prints things to your output bar, so the first thing wrong with your script is that it is printing stuff to the wrong area, for instance

print("Hi i'm bob")

would give this to the output bar: Hi i'm bob. Players can't see the output bar unless they use the Developer Console, which can be opened with F9. The print function can also print variables, even variables containing integers!

local zombie101 = 123
print(zombie101)

this would print 123 to your output bar.

The way you would print something to a player's screen, is to create a hint. A hint is a Roblox instance that can contain text. Creating a hint is simple! You just do

local newHint = Instance.new("Hint") --we need to assign it to a variable for future use

Now we can change the "Text" property of hint using

newHint.Text = "You Win"

Now we need to put the hint in Workspace, so everyone can see your new hint!

newHint.Parent = game.Workspace

Now on to part two of your script! Your function win() does not return a true or false value. It returns nothing at all! That means using print(win()) would do nothing! so the first thing we will do is return true after your function

function Win() --functions should start with a capital letter
	local win = false
	local newHint = Instance.new("Hint")
	newHint.Text = "You Win"
	newHint.Parent = game.Workspace
	win = true
	return win --now every time Win() is called, it will return the value of win!
end

Next we must discuss the use of true and false, true and false are Boolean values. Meaning they can only be true or false. Certain things do not return Boolean values, such as scripts. If you want to disable a script, you should probably move it to the ServerStorage The ServerStorage is an area of your game where you can store things. In the ServerStorage, scripts don't run, so it technically disables it for you.

local serverStore = game:GetService("ServerStorage") --this gets ServerStorage ready
disaster.Parent = serverStore --puts the script in ServerStorage

Now for your finished product!

local humanoid = workspace:FindFirstChild("Zombie").Humanoid --FindFirstChild is less buggy
local disaster = workspace:FindFirstChild ("Disaster Script")
 local serverStore = game:GetService("ServerStorage") --gets ServerStorage ready

function Win()
	local win = false
	local newHint = Instance.new("Hint")
	newHint.Text = "You Win"
	newHint.Parent = game.Workspace
	win = true
	return win --now every time Win() is called, it will return the value of win!
end

if humanoid.Health == 0 then --capitalize Health
    	print (Win())
        	if Win() == true then
    			disaster.Parent = serverStore --puts the script in ServerStorage	        
		end
   end 
--you had an extra end

2 comments

0

I'm not saying this is a bad answer, because this is a great answer. But it might be worth noting that Hints are deprecated. http://wiki.roblox.com/index.php?title=API:Class/Hint

0

Oh, well I guess that makes me a hipster. What is the new hint anyways?

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