Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

NPC Quest Script - Value Not Updating Correctly?

Asked by 2 years ago
Edited 2 years ago

Hello, I am working on an NPC quest script that relies on instances of number values to inform the script what information to display in a chat GUI for said script. It seems as though this value is only changing within the script, but not the game itself.

The NPC is being cloned from within a folder in this local script, which resides in the StarterPlayerScripts tab.

Here is the script itself:

wait(2)

local Player = game.Players.LocalPlayer

local PlayerGui = Player.PlayerGui

local PlayerCharacter = game.Workspace[Player.Name]

local Children = PlayerCharacter:GetChildren()

local WaitToTouch = false

for i,v in pairs(Children) do
    wait()
    if v.ClassName == "Part" then
        v.Touched:Connect(function(Touched)
            if WaitToTouch == false then
                if Touched.Name == "FriendlyTouch" then
                    WaitToTouch = true
                    print(Touched)
                    if Touched.Parent.Quests then

                        local Quests = Touched.Parent.Quests

                        local QuestID = Quests.QuestID.Value
                        local CurrentQuest = Quests["Quest"..QuestID]

                        local QuestPartID = CurrentQuest.QuestPartID.Value

                        local CurrentPart = CurrentQuest["Part"..QuestPartID]

                        if CurrentPart then
                            if CurrentPart.Chat then
                                local CurrentQuestPartChat = CurrentPart.Chat
                                local NPCChatGui = PlayerGui.NPCChatGui
                                local NPCChatGuiName = NPCChatGui.Frame.NPCName
                                local NPCChatGuiText = NPCChatGui.Frame.NPCText
                                NPCChatGuiName.Text = Touched.Parent.Name
                                NPCChatGuiText.Text = CurrentQuestPartChat.Value
                                NPCChatGui.Frame.NPCText.MouseButton1Down:Connect(function(Clicked)
                                    QuestPartID = QuestPartID + 1
                                    print(QuestPartID)
                                    print(CurrentPart)
                                    NPCChatGuiName.Text = "[NPC_Name]"
                                    NPCChatGuiText.Text = "[NPC_Text]"
                                    WaitToTouch = false
                                end)
                            end
                        end
                    end
                end
            end
        end)
    end
end

Here is the output:

  14:29:49.613  Hello world!  -  Client - LocalScript:1
  14:30:01.261  FriendlyTouch  -  Client - LocalScript:20
  14:30:02.893  2  -  Client - LocalScript:42
  14:30:02.893  Part1  -  Client - LocalScript:43
  14:30:08.993  FriendlyTouch  -  Client - LocalScript:20
  14:30:10.076  2  -  Client - LocalScript:42
  14:30:10.076  Part1  -  Client - LocalScript:43
  14:30:10.077  3  -  Client - LocalScript:42
  14:30:10.077  Part1  -  Client - LocalScript:43
  14:30:10.978  FriendlyTouch  -  Client - LocalScript:20
  14:30:11.777  2  -  Client - LocalScript:42
  14:30:11.777  Part1  -  Client - LocalScript:43
  14:30:11.778  3  -  Client - LocalScript:42
  14:30:11.778  Part1  -  Client - LocalScript:43
  14:30:11.779  4  -  Client - LocalScript:42
  14:30:11.779  Part1  -  Client - LocalScript:43
  14:30:12.411  FriendlyTouch  -  Client - LocalScript:20
  14:30:13.176  2  -  Client - LocalScript:42
  14:30:13.176  Part1  -  Client - LocalScript:43
  14:30:13.177  3  -  Client - LocalScript:42
  14:30:13.177  Part1  -  Client - LocalScript:43
  14:30:13.178  4  -  Client - LocalScript:42
  14:30:13.179  Part1  -  Client - LocalScript:43
  14:30:13.179  5  -  Client - LocalScript:42
  14:30:13.180  Part1  -  Client - LocalScript:43

Here is a video in case that helps for visualization:

https://youtu.be/0NVAj8ObYqo

Thank you in advance for your help!

1 answer

Log in to vote
0
Answered by 2 years ago

Okay, In case anyone has a similar issue, I figured it out. It seems there is some limitation with how many variables ROBLOX can pass data through. I changed line 41 to the following:

Touched.Parent.Quests["Quest"..QuestID].QuestPartID.Value = Touched.Parent.Quests["Quest"..QuestID].QuestPartID.Value + 1

I also had no debounce for clicking on the GUI button, which caused the script to add to the value in a weird way. After having committed both of these changes, this issue is now completely resolved.

Ad

Answer this question