How do I access PlayerGui within a Module Script and how can I add attacks to enemies?

Hello Scripters!

The code below this text is the code of a Module Script that controls the Turn-Based PVP my Bullet-Hell x Turn-Based RPG game is going to have. The issues are that I am wondering how to access the PlayerGui inside of the Module Script and how do I create attacks to enemies to after the player is done doing their turn, the enemy will do their turn and so on.
(Sorry if the code is a bit sloppy, I’m new to this kind of thing.)

local Rep = game:GetService("ReplicatedStorage")

local TurnBasedModule = {}

local Enemies = {}

function TurnBasedModule.SpawnEntity(Entity)
	print("User wants to spawn "..Entity)
	local mobExist = Rep.Enemies:WaitForChild(Entity)
	
	if mobExist then
		local NewEntity = mobExist:Clone()
		NewEntity.HumanoidRootPart.CFrame = workspace.SpawnPoint1.CFrame
		NewEntity.HumanoidRootPart.CFrame = NewEntity.HumanoidRootPart.CFrame + Vector3.new(0, 3, 0)
		NewEntity.Parent = workspace
	else
		wait(Entity.." DOESN'T EXIST!")
	end
end



return TurnBasedModule

1 Like

Use game:GetService("Players"), find the appropriate name of the player, and access “PlayerGui”.

local Players = game:GetService("Players")

local PlayerGui = Players:FindFirstChild("PlayerName").PlayerGui

Can’t test and make a real example as I cannot access my laptop at the moment.

Alright then, I’ll wait for you so you can provide me an example.

if the module is being required and being used from the client, you can just use game.Players.LocalPlayer.PlayerGui

2 Likes

Well, I am using a Part with a ProximityPrompt, but the prompt allows the Server script to access Client-Only functions and commands so I guess that wouldn’t really be much of a problem. Oh and also, mind if you can give me an example of how?