Hello Devs,
I have this module script here but I cant get the local player.
I would like some help to get this done.
local module = {}
function module.PlrsBanned(Plr)
local Button = Plr.PlayerGui:WaitForChild("AdministratorSaves").PlrBanVal
Button = Button + 1
end
return module
any help is appreciated!
and here is the error it is giving me
StarterGui.AdministratorPanel.Scripts.Modules.Home:3: attempt to index nil with 'PlayerGui' - Client - Home:3
Stack Begin - Studio
Script 'StarterGui.AdministratorPanel.Scripts.Modules.Home', Line 3 - function PlrsBanned - Studio - Home:3
Script 'Players.Paysallday44.PlayerGui.ScreenGui.TextButton.LocalScript', Line 4
local Home = require(game.StarterGui.AdministratorPanel.Scripts.Modules.Home)
script.Parent.MouseButton1Click:Connect(function()
Home.PlrsBanned()
end)
```
local Home = require(game.Players.LocalPlayer.PlayerGui.AdministratorPanel.Scripts.Modules.Home)
script.Parent.MouseButton1Click:Connect(function()
Home.PlrsBanned(game.Players.LocalPlayer)
end)
local module = {}
function module.PlrsBanned(Plr)
local Button = Plr.PlayerGui:WaitForChild("AdministratorSaves").PlrBanVal
Button = Button + 1
end
return module
return function(Player)
local Button = Player["PlayerGui"]:WaitForChild("AdministratorSaves")["PlrBanVal"]
Button = Button + 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"]) -- is the module script in this instance? if so then do ["ModuleScript"]
local Button = script["Parent"]
Button["MouseButton1Click"]:Connect(function()
Home(LocalPlayer)
end)
Edit: Wait, are you even requiring the ModuleScript itself?
Can you post a screenshot of your workspace where the ModuleScript is and where the LocalScript is?
Edit 2: NVM, that was me being a dumb dumb, I forgot you can rename Instances.
Infinite yield possible on 'Players.Paysallday44.PlayerGui:WaitForChild("AdministratorSaves")' - Studio
Stack Begin - Studio
Script 'StarterGui.AdministratorPanel.Scripts.Modules.Home', Line 3 - function PlrsBanned - Studio - Home:3
Script 'Players.Paysallday44.PlayerGui.ScreenGui.TextButton.LocalScript', Line 4 - Studio - LocalScript:4
Stack End
local module = {}
function module.PlrsBanned()
if game.Players.LocalPlayer then -- If module got required from local script then
local Plr = game.Players.LocalPlayer
local Button = Plr.PlayerGui:WaitForChild("AdministratorSaves").PlrBanVal
Button = Button + 1
else
-- module got required from server script.
end
end
return module
Ah,
So the ModuleScript was looking for “AdministratorSaves” Instance in the PlayerGUI but it can’t find it, hence the reason for yielding infinitely.
You can skip this part but this is what i tried: ModuleScript
return function(Player)
local Button = Player["PlayerGui"]:WaitForChild("AdministratorSaves")
print(Button["Name"])
end
LocalScript
local StarterGUI = game:GetService("StarterGui")
local Players = game:GetService("Players")
local LocalPlayer = Players["LocalPlayer"]
local Home = require(StarterGUI["AdministratorPanel"]["Scripts"]["Modules"]["Home"]) -- is the module script in this instance? if so then do ["ModuleScript"]
local Button = script["Parent"]
local AdministratorSaves = Instance.new("ScreenGui")
AdministratorSaves["Name"] = "AdministratorSaves"
AdministratorSaves["Parent"] = LocalPlayer["PlayerGui"]
Button["MouseButton1Click"]:Connect(function()
Home(LocalPlayer)
end)
Try to tweak your Instance.new to this:
local AdministratorSaves = Instance.new("ScreenGui") -- change it if its not a ScreenGui
AdministratorSaves["Name"] = "AdministratorSaves"
AdministratorSaves["Parent"] = LocalPlayer["PlayerGui"]