I am trying to give a player a choice to Accept or Decline a quest through the use of a GUI that starts off invisible
I am using a ModuleScript that is inside of an NPC within a folder within Workspace. e.g. game.Workspace.Folder.NPCModel.ModuleScript
I'm also using a LocalScript within a ScreenGUI inside of StarterGUI e.g. game.StarterGui.ScreenGUI.LocalScript
The LocalScript works perfectly and its purpose is to look at the ModuleScript and use the text within it as the text that goes inside of a TextLabel. The TextLabel is inside of a frame with the same parent as the LocalScript.
When I try to make a simple function to turn frame visible it doesn't work nor does it error. However when I change the function to define a variable ( frame ) and then print frame.Visible It works perfectly and tells me whether or not the frame is visible.
Then after that I tried setting frame to visible after I print whether or not it is visible. After I set frame to Visible it still doesn't become visible so I print frame.Visible again and it tells me it is visible when it is very clearly not
This is the ModuleScript where the problem is happening in
local frame = game.StarterGui.QuestGUI.DialogueHolder.Choices local NPCLines = { {"What's up kid?",0.01,nil}, {"Those bandits from the outskirts are back giving the townspeople trouble again..",0.01,nil}, {"Why dont you go show them who they're messing with",0.01,nil}, {"They're probably carrying some cash too",0.01,nil}, {"You up for it?",0.01,function() wait(0.1) print(frame.Visible) wait(1) frame.Visible = true print(frame.Visible) end}, {"Good man!",0.01, nil}, } return NPCLines
This is the local script where the dialogue is handled
local UIS = game:GetService('UserInputService') --local playerservice = game:GetService('Players') --local player = playerservice.PlayerAdded << Not needed in a local script local player = game.Players.LocalPlayer local char = player.CharacterAdded:Wait() local hum = char:WaitForChild('Humanoid') local isinrange = nil local ischatting = false local line = 1 local istalking = false local dialogues = nil --local hws = hum.Walkspeed local function onInputBegan(input,gameProcessed) if input.UserInputType == Enum.UserInputType.Keyboard then local keyPressed = input.KeyCode if keyPressed == Enum.KeyCode.E then if isinrange ~= nil and not istalking then if ischatting == false then line = 1 ischatting = true dialogues = require(isinrange.Lines) hum.WalkSpeed = 0 script.Parent.DialogueHolder.Dialogue.Text = "" script.Parent.DialogueHolder:TweenPosition(UDim2.new(0.5,0,0.99,0),Enum.EasingDirection.Out,Enum.EasingStyle.Back,0.5,true) wait(0.5) local Cline = dialogues[line] istalking = true for i = 1,#Cline[1] do script.Parent.DialogueHolder.Dialogue.Text = string.sub(Cline[1],0,i) wait(Cline[2]) end if Cline[3]then Cline[3]() end istalking = false line = line+1 else local Cline = dialogues[line] if line > #dialogues then script.Parent.DialogueHolder:TweenPosition(UDim2.new(0.5,0,2,0),Enum.EasingDirection.Out,Enum.EasingStyle.Back,1.5,true) hum.WalkSpeed = 16 dialogues = nil ischatting = false else local Cline = dialogues[line] istalking = true for i = 1,#Cline[1] do script.Parent.DialogueHolder.Dialogue.Text = string.sub(Cline[1],0,i) wait(Cline[2]) end if Cline[3]then Cline[3]() end istalking = false line = line+1 end end end end end end UIS.InputBegan:Connect(onInputBegan) while true do wait() if ischatting == false then isinrange = nil for i,v in pairs(game.Workspace.QuestNPCs:GetChildren()) do if(char.HumanoidRootPart.Position-v.HumanoidRootPart.Position).magnitude <= 10 then isinrange = v end end end end UIS.InputBegan:Connect(onInputBegan)
I really don't know what to do at this point or where to even start.