How to get the local player in a module script

administratorSaves is actually a folder sorry for not stating that

In that case:

local AdministratorSaves = Instance.new("Folder")
AdministratorSaves["Name"] = "AdministratorSaves"
AdministratorSaves["Parent"] = LocalPlayer["PlayerGui"]
2 Likes

Question.
why are you using Instance["property/instance"] (I know it wont give errors its same as normal way, just curious)
instead of using Instance.property?

2 Likes

It feels alot more cleaner to me that way. Better Readability.

2 Likes

Ok the script works thanks for the help!!
I changed some of the code a bit but it still works

1 Like

Hey could you help me with this??

Button["MouseButton1Click"]:Connect(function()
    Home(LocalPlayer)
    LocalPlayer["PlayerGui"]["AdministratorPanel"]:WaitForChild("PlrBanVal").Changed:Connect(function()
        game.StarterGui.AdministratorPanel.Gui.Panel.OPFrame.HomeFrame.ScrollingFrame.PlrsBanned.Count.Text = LocalPlayer.PlayerGui.AdministratorPanel:WaitForChild("PlrBanVal")
    end)

    game.StarterGui.AdministratorPanel.Gui.Panel.OPFrame.HomeFrame.ScrollingFrame.PlrsBanned.Count.Text = LocalPlayer.PlayerGui.AdministratorPanel:WaitForChild("PlrBanVal")
end)

I want the count text to change with the value and it gives this error

 PlrBanVal  -  Client - Home:3
  Infinite yield possible on 'Players.Paysallday44.PlayerGui.AdministratorPanel:WaitForChild("PlrBanVal")'  -  Studio
 Stack Begin  -  Studio
  Script 'Players.Paysallday44.PlayerGui.ScreenGui.TextButton.LocalScript', Line 10  -  Studio - LocalScript:10
  Stack End  -  Studio

Oh… this one is simple.

So, instead of this:

We can do something like:

PlrBanVal["Changed"]:Connect(function(NewValue)
	Count["Text"] = NewValue
end)

Also, try to save the value, you’re saving, in datastores, it’s much more efficient but just for this demo, ill make a simple int value and assign the value to it every time the button is pressed.

Here:

ModuleScript

return function(Player)
	local Button = Player["PlayerGui"]:WaitForChild("AdministratorSaves")["PlrBanVal"]
	Button["Value"] = Button["Value"] + 1
end

LocalScript

local StarterGUI	= game:GetService("StarterGui")
local Players		= game:GetService("Players")
local LocalPlayer	= Players["LocalPlayer"]

local Home			= require(StarterGUI["AdministratorPanel"]["Scripts"]["Modules"]["Home"])

local Button		= script["Parent"]

local Folder		= Instance.new("Folder")
Folder["Name"]		= "AdministratorSaves"
Folder["Parent"]	= LocalPlayer["PlayerGui"]

local IntValue		= Instance.new("IntValue") -- creating a intvalue to save your counts
IntValue["Name"]	= "PlrBanVal"
IntValue["Value"]	= 0 -- this is a client only, use server-sided value assigning methods if this is for an admin panel
IntValue["Parent"]	= Folder

--[[
		I did a rough/messy job of assigning objects, so try to do it in a more clean manner if you like.
--]]
local PlayerGUI		= LocalPlayer:WaitForChild("PlayerGui")
local Panel			= PlayerGUI["AdministratorPanel"]["Gui"]["Panel"]
local HomeFrame		= Panel["OPFrame"]["HomeFrame"]
local Count			= HomeFrame["ScrollingFrame"]["PlrsBanned"]["Count"]

-- again, this is client sided, not a good way to use it in a admin panel but here
IntValue["Changed"]:Connect(function(NewValue)
	Count["Text"] = NewValue
end)

Button["MouseButton1Click"]:Connect(function()
	Home(LocalPlayer)
end)

Edit: Added some Explanation. (it still lacks a lot of explanation because I am bad at, well, explaining.)

1 Like

thank you very much i really appreciate the help