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

my modulescript is a fail, can someone tell me what is wrong?

here is my ModuleScript:

game.Players.PlayerAdded:connect(function(player)-- this is just so I can declare the player
	plr = player.Name
end)
function waitforit(object)
	game.Workspace:WaitForChild(object)
end

function message(parent ,text, staytime)
	msg = Instance.new("Message")
	msg.Parent = parent
	msg.Text = text
	if staytime > 0 then
		wait(staytime)
		msg:destroy()
	end
end

function hint(text, staytime)
 playergui = game.Players.plr.PlayerGui
gui = Instance.new("ScreenGui")
gui.Parent = playergui
gui1 = Instance.new("TextLabel")
gui1.Text = text
gui1.Size.X = 1000
gui1.Size.Y = 50
if staytime > 0 then
	wait(staytime)
	gui1:destoy()
	gui:destoy()
end
end

now I want to be able to call a function like this:simplemodule.message("game.Workspace", "hello", 30) also none of these work can someone tell me what I did wrong?

2 answers

What happened was you didn't return a table. Tables are required to add functions like simplemodule.message()

local tbl = {}
game.Players.PlayerAdded:connect(function(player)-- this is just so I can declare the player
    plr = player.Name
end)
-- You can also use function tbl:waitforit(object) so it can be a real method.
function tbl.waitforit(object)
    game.Workspace:WaitForChild(object)
end

function tbl.message(parent ,text, staytime)
    msg = Instance.new("Message")
    msg.Parent = parent
    msg.Text = text
    if staytime > 0 then
        wait(staytime)
        msg:destroy()
    end
end

function tbl.hint(text, staytime)
 playergui = game.Players.plr.PlayerGui
gui = Instance.new("ScreenGui")
gui.Parent = playergui
gui1 = Instance.new("TextLabel")
gui1.Text = text
gui1.Size.X = 1000
gui1.Size.Y = 50
if staytime > 0 then
    wait(staytime)
    gui1:destoy()
    gui:destoy()
end
end

return tbl

If I helped accept me as an answer and vote me up. Thank you! Also, sorry if any of this info is wrong. Its probably because I'm tired. D:

2 comments

0

can i put the hint in every players gui using game.Players:GetChildren().playergui... etc.

0

Change the name of the hint gui to something like HintGui. Then loop through the players and check if the HintGui exists if it does do nothing otherwise just make the hint gui like in the hint function. Hopefully that's right.

Game.Players.PlayerAdded:connect(function(player)
plr = Game.Players.LocalPlayer
end)

function waitforit(object)
game.Workspace:WaitForChild("	Object")
end

function hint(Parent, text,  StayTime)
msg = instance.new("Message")
msg.Parent = game.Workspace -- beacuse workspace is where everything goes.
msg.Text = "Wat is your text here"
if staytime > 0 then
wait() --  put seconds
msg:Destroy() -- beacuse msg was on Every Line.
   end
end


function hint(text, StayTime)

gui = instance.new("ScreenGUI")
gui.Parent = Game.StarterGUI -- you forgot the frame.
Frame = Instance.new("Frame")
TextLabel = Instance.new("TextLabel")
gui.Text = "" -- put your text between the ""
gui.Size.X = 1000
gui.Size.Y = 50

if staytime > 0 then
wait() -- put seconds between () like the code UnTop
Frame:Destroy()
TextLabel:Destroy()
gui:Destroy()

end
end
-- np. also Local Script.



6 comments

0

Some Things are spaced like ("Object") its not my fault.

0

oh you put enw instead of new heehee

0

Lol like i said its not me its the website.

0

also i need to know how to actualy use it like this "simplemodule.message("hello", 3)"

0

number of probs but i hope it works

0

Make this a local script im editing noe.

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