Hello, I’m creating a game that uses an NPC that gives you different dialogue depending on how many times you’ve talked to him, for the first part of the script or the first time talking/interacting with him, it works fine, however when you do it the second time the for i, v in pairs function doesn’t even run and is just skipped entirely, with only 1 error occuring that says: "Frame is not a valid member of ScreenGui “ScreenGui1”. The bool values in my case : FirstTalk And tutorialfinished are both set to false at the start and function perfectly.
Here is the script:
local debounce = false
local cooldown = 5
local Messages = {"Yo dude", "You wanna collect taxes or something?", "Use the car outside and go to houses that haven't yet payed their taxes", "Good Luck and come back to me after your first job."}
local Messages2 = {"lol good job bud", "You can use the shop in the top right of your screen to buy cool new vehichles and stuff with tax bucks", "Now go get us more tax dollars and stuff", "oh btw sometimes we get robbed and stuff."}
local Reply1 = {"idc", "go do it anyways"}
local Reply2 = {"alr gl"}
game:GetService("ReplicatedStorage").Chats.Joe1.OnClientEvent:Connect(function(hit)
print(debounce)
if debounce == false then
debounce = true
local GUI = script.Parent.ScreenGui1:Clone()
local Player = hit
local Rig = game.Workspace.NPCJoe:Clone()
GUI.Parent = script.Parent
GUI.Frame.NPC.Text = "Joe"
GUI.Enabled = true
script.Parent.Parent.Character.Humanoid.WalkSpeed = 0
Rig.Parent = GUI.Frame.ViewportFrame
if script.Parent.ScreenGui1.FirstTalk.Value == false then
for i, v in pairs(Messages) do
for i = 1, string.len(v) do wait(.025)
script.Parent.NPC_70:Play()
GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
end
wait(1)
end
GUI.Frame.Yes.Visible = true
GUI.Frame.No.Visible = true
elseif script.Parent.ScreenGui1.FirstTalk.Value == true and script.Parent.ScreenGui1.TutorialFinished.Value == false then
print("cago")
for i, v in pairs(Messages2) do
for i = 1, string.len(v) do wait(.025)
script.Parent.NPC_70:Play()
script.Parent.ScreenGui1.Frame.Dialogue.Text = string.sub(v, 1, i)
end
wait(1)
script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
GUI:Destroy()
end
end
GUI.Frame.Yes.MouseButton1Down:Connect(function(plr)
GUI.Frame.Yes.Visible = false
GUI.Frame.No.Visible = false
for i, v in pairs(Reply2) do
for i = 1, string.len(v) do wait(.025)
script.Parent.NPC_70:Play()
GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
end
wait(1)
end
script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
debounce = false
GUI:Destroy()
script.Parent.ScreenGui1.FirstTalk.Value = true
end)
GUI.Frame.No.MouseButton1Down:Connect(function(plr)
GUI.Frame.Yes.Visible = false
GUI.Frame.No.Visible = false
for i, v in pairs(Reply1) do
for i = 1, string.len(v) do wait(.025)
script.Parent.NPC_70:Play()
GUI.Frame.Dialogue.Text = string.sub(v, 1, i)
end
wait(1)
end
script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
debounce = false
GUI:Destroy()
script.Parent.ScreenGui1.FirstTalk.Value = true
end)
end
end)
Video : https://streamable.com/bkti03
So far I’ve looked through the devforum to find similar experiences to mine but haven’t got anywhere.
I’ve tried using things like :WaitForChild and other ways to path to my frame but it doesn’t seem to be working.
If anyone has had something similar happen to them and/or can help I would be greatly appreciative