Part doesnt detect module line on touch

so basically, im trying to get a module function work when a specific part i made is touched, but when i touch it doesnt work. how do i fix this?

the text lines from my module
local Players = game:GetService("Players")

local client = Players.LocalPlayer

local ChapterText = {}

function ChapterText.ClassicChapterText(Text: string)

local ScreenGui ="ScreenGui")

ScreenGui.Name = "ChapterEntrance"

local CText ="TextLabel")

CText.Name = "ChapterName"

ScreenGui.Parent = game.StarterGui

CText.Parent = ScreenGui

CText.Text = Text


return ChapterText
the part touch script
local Players = game:GetService("Players")
local text = require(game.ReplicatedStorage.ChapterTextModule)

	-- make sure the part still exists
	if not part.Parent then return end

	-- make sure it's a humanoid
	local h = part.Parent:FindFirstChild("Humanoid")
	local player = Players:GetPlayerFromCharacter(part.Parent)
	if not h then return end
    text.ClassicChapterText("Chapter #dsad")
1 Like

You don’t ever set the ScreenGui parent to client.PlayerGui, so it wouldn’t render logically.

but it works when i delete the whole part touch stuff.

You’re wrong. It works because the startergui is what is cloned into the player whenever they join the game. That code, because it doesn’t rely on an event, puts the screengui into the playergui before it’s cloned, so when it is cloned, it will show. You need to put the screengui into client.PlayerGui, not game.StarterGui.

:confused: it gives a error when i do that

Do you do this on the client or on the server? If it’s the client, there is no Players.LocalPlayer.
You’ll have to change your module to accept a client argument, which would be the player, and pass it from the part touch script when calling text#ClassicChapterText.

1 Like

because im doing the touch on a normal script because workspace cannot run local scripts you know