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

Help me out please??

So I have a script here:

msg = game.Workspace.Message
text = msg.Text

function Hint()
	local hint = Instance.new("Hint")
	hint.Name="Hint"
	hint.Parent=game.Workspace
	hint.Text="Game in progress..."
end

while true do
	msg.Text="Loading."
	wait(4)
	msg.Text="Starting new game"
	wait(3)
	msg.Text="Murderer Mode: '1 life Murderer' is chosen."
	wait(2)
	msg.Text="Everyone is murderer, Good Luck!"
	wait(3)
	msg:Destroy()
	Hint()
	wait(120)
	Hint:Destroy()
	wait(1)
	msg.Text="Game over."
	wait(3)
	msg:Destroy()
end

From line 21 and below, it won't work.. So what 21 and below is trying to do is to time the game. 120 seconds(2 minutes), after 120 seconds, the game is over. and the Message saves "Game over." and does the loop over and over again. But doesn't work :( Why?

1 answer

✓ Accepted answer

Remove the statement in line 2, as it is not used and I doubt you could assign variables to an object's property; only it's value(s).

On line 20, you destroyed your message. You can't edit the text within it if you destroyed it.

If you want to destroy your message, yet still want a message after it is destroyed, remove the existing message and create another function to make a new one just like you did with 'Hint'.

function Hint()
	local hint = Instance.new("Hint", game.Workspace)
	hint.Text="Game in progress..."
end

function Message()
	msg = Instance.new("Message", game.Workspace)
end

while true do
	Message()			-- Message created
	msg.Text = "Loading."
	wait(4)
	msg.Text="Starting new game"
	wait(3)
	msg.Text="Murderer Mode: '1 life Murderer' is chosen."
	wait(2)
	msg.Text="Everyone is murderer, Good Luck!"
	wait(3)
	msg:Destroy()		--Message destroyed
	Hint()
	wait(120)
	Hint:Destroy()
	wait(1)
	Message()			-- Message created
	msg.Text="Game over."
	wait(3)
	msg:Destroy()		-- Message destroyed
end
-- We're not done yet. Read on.

Speaking of the Hint function, in line 23, the script is trying to destroy 'Hint', which is a nil variable (a variable without an assignment).

You can either:

  • Make the 'hint' variable global and un-capitalize the 'Hint' that uses the 'destroy' method (to convert the nil variable into the correct variable):
function Hint()
	hint = Instance.new("Hint", game.Workspace)
	hint.Text="Game in progress..."
end

function Message()
	msg = Instance.new("Message", game.Workspace)
end

while true do
	Message()
	msg.Text = "Loading."
	wait(4)
	msg.Text="Starting new game"
	wait(3)
	msg.Text="Murderer Mode: '1 life Murderer' is chosen."
	wait(2)
	msg.Text="Everyone is murderer, Good Luck!"
	wait(3)
	msg:Destroy()
	Hint()
	wait(120)
	hint:Destroy()
	wait(1)
	Message()
	msg.Text="Game over."
	wait(3)
	msg:Destroy()
end

or

  • Keep the local variable, but destroy the existing hint in the Workspace:
function Hint()
	local hint = Instance.new("Hint", game.Workspace)
	hint.Text="Game in progress..."
end

function Message()
	msg = Instance.new("Message", game.Workspace)
end

while true do
	Message()
	msg.Text = "Loading."
	wait(4)
	msg.Text="Starting new game"
	wait(3)
	msg.Text="Murderer Mode: '1 life Murderer' is chosen."
	wait(2)
	msg.Text="Everyone is murderer, Good Luck!"
	wait(3)
	msg:Destroy()
	Hint()
	wait(120)
	game.Workspace.Hint:Destroy()
	wait(1)
	Message()
	msg.Text="Game over."
	wait(3)
	msg:Destroy()
end

Either will do the job, but using the latter of the two choices will destroy the variables it is assigned to, just in case if you have more than one Message or Hint objects.

1 comment

0

Thank you :) It helped a lot.

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