generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How to call this global function without messups?

Previous Thread :: Next Thread 
frriend is not online. frriend
Joined: 07 Feb 2010
Total Posts: 577
07 Oct 2015 10:13 PM
So i have this code inside of a gui in every player.. (Public Script)

_G.alert = function(title, inform, plr)
local player = game.Players:FindFirstChild(plr.Name)

if player then
script.Parent.Window.Alert.Text = title
script.Parent.Window.Info.Text = inform

local frame = player.PlayerGui.Alert.Window
frame:TweenPosition(UDim2.new(0.5, -100, 0.5, -50), "Out", "Quad", 1)
wait(4)
frame:TweenPosition(UDim2.new(0.5, -100, -1, 0), "Out", "Quad", 1)
wait(4)
frame.Position = UDim2.new(0.5, -100, 1, 0)
end
end

and i call the function using this..

for _, player in ipairs(game.Players:GetPlayers()) do
spawn(function() _G.alert("Supply Crates Dropping", "Supply crates have been dropped! Fight for them!", player)end)
end

but for some reason, only a few players get the message, and others get the text from another message on another script..

Any help? I'm so lost on why this is happening.. Its my first time with global functions.
Report Abuse
frriend is not online. frriend
Joined: 07 Feb 2010
Total Posts: 577
07 Oct 2015 10:18 PM
I need urgent help. I don't have much time.
Report Abuse
frriend is not online. frriend
Joined: 07 Feb 2010
Total Posts: 577
07 Oct 2015 10:29 PM
Please help. Bump.
Report Abuse
frriend is not online. frriend
Joined: 07 Feb 2010
Total Posts: 577
08 Oct 2015 05:39 PM
Bump.
Report Abuse
teamkilled is not online. teamkilled
Joined: 14 Apr 2013
Total Posts: 1748
08 Oct 2015 05:41 PM
Global functions are global functions for a reason, they are global.

When you put a global function inside of every player, it redefines the global function for EVERYONE in the game. That means, the newest person to join is the "player" variable.

So, when you run the script on everyone, that one person is getting the message because they have redefined the global function
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
08 Oct 2015 05:43 PM
Incorrect term
This is a function in a shared table


Red Blossoms
Report Abuse
teamkilled is not online. teamkilled
Joined: 14 Apr 2013
Total Posts: 1748
08 Oct 2015 05:44 PM
@ray, it's a function in a global table, but according to the wiki, that's what a global function is

it's either or
http://wiki.roblox.com/index.php/Global_function
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
08 Oct 2015 05:46 PM
Nope

A global function is a global variable:

x=function()
print("hello")
end

Meaning it is accessible in the global scope


Red Blossoms
Report Abuse
teamkilled is not online. teamkilled
Joined: 14 Apr 2013
Total Posts: 1748
08 Oct 2015 05:49 PM
According to the wiki, a function inside a global variable is a global function

so _G.variable = function() is a global function (because it is a function in a global variable)
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
08 Oct 2015 05:50 PM
According to the Lua website

lua.
org/pil
/1.2.html


Red Blossoms
Report Abuse
teamkilled is not online. teamkilled
Joined: 14 Apr 2013
Total Posts: 1748
08 Oct 2015 05:52 PM
I was talking about global as in the global table, not global scope of one script
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
08 Oct 2015 05:55 PM
Well now you know to refer to it as a shared function


Red Blossoms
Report Abuse
Dralian is not online. Dralian
Joined: 21 Mar 2013
Total Posts: 7624
08 Oct 2015 06:37 PM
"According to the Lua website

lua.
org/pil
/1.2.html"

But Roblox Lua is modified differently.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image