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 = Instance.new("ScreenGui")

ScreenGui.Name = "ChapterEntrance"

local CText = Instance.new("TextLabel")

CText.Name = "ChapterName"

ScreenGui.Parent = game.StarterGui

CText.Parent = ScreenGui


CText.Text = Text

end

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


script.Parent.Touched:Connect(function(part)
	-- 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)
	print(player)
	if not h then return end
    text.ClassicChapterText("Chapter #dsad")
	script.Parent:Destroy()
end)
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
image

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

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