NPC Thoughts Module Script

Hello Everyone,
I’m making a system where NPC will have “thoughts”, happiness, hunger, thirst, thrill. I have the ui able to open and working when I open it, but when I have multiple NPC’s it always comes up with the same chart, same numbers. This may be kind of confusing to read so if you guys would like screenshots or videos I can send that too, any help is very appreciated.
Thanks!

This is pretty late sending this (1h+?), but can you provide us with some code?

1 Like

Yep! I could also send a video explaining what I need help with if thats easier.

Script inside NPC:

local clickD = script.Parent.HumanoidRootPart.ClickDetector
local ONTG = game:GetService("ReplicatedStorage").RemoteEvents.OpenNPCThoughtsGui

clickD.MouseClick:Connect(function(player)
	ONTG:FireClient(player)
	print("OpenNPCThoughtsGui event fired.")
end)

Module Script inside NPC:

local ThoughtLevels = {
	math.random(1,100),
	math.random(1,100),
	math.random(1,100),
	math.random(1,100),
	script.Parent.NPCName.Value
}

return ThoughtLevels

Script inside GUI:

local ONTG = game:GetService("ReplicatedStorage").RemoteEvents.OpenNPCThoughtsGui

local ThoughtLevels = require(game.Workspace.MaleNPC.ThoughtsModule)

local HappinessBar = script.Parent.HappinessBackgroundBar.HappinessBar
local HungerBar = script.Parent.HungerBackgroundBar.HungerBar
local ThirstBar = script.Parent.ThirstBackgroundBar.ThirstBar
local ThrillBar = script.Parent.ThrillBackgroundBar.ThrillBar

local NPCName = script.Parent.NPCName

print(ThoughtLevels[1])
print(ThoughtLevels[2])
print(ThoughtLevels[3])
print(ThoughtLevels[4])

ONTG.OnClientEvent:Connect(function()
	script.Parent.Visible = true
	HappinessBar.Size = UDim2.new(0,ThoughtLevels[1]*5,0,25)
	HungerBar.Size = UDim2.new(0,ThoughtLevels[2]*5,0,25)
	ThirstBar.Size = UDim2.new(0,ThoughtLevels[3]*5,0,25)
	ThrillBar.Size = UDim2.new(0,ThoughtLevels[4]*5,0,25)
	NPCName.Text = ThoughtLevels[5]
end)
local ThoughtLevels = require(game.Workspace.MaleNPC.ThoughtsModule)

Unless I misunderstand the structure of your code, you are opening a specific modulescript here. But you don’t ever require the script from another NPC. I see no way that your code lets the gui know which character is selected. It just by default gets a specific one from the workspace.

Personally for this, I would use attributes rather than module scripts. But you still need a way to pass which NPC is selected across.

1 Like

Yeah that’s what I need to fix, is there anyway I can restructure it too work?

The easiest way would be to have the client just open the gui reading the attributes without having the server tell it. It would require you to set up a script that assigns all characters random attributes from the server but then you can check from the client when clicked.