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

Dialog Script not working, not animating text????

Asked by 6 years ago
Edited 6 years ago

I have a dialog system and I need it to show the player what the NPC is saying. I noticed in ROBLOX server version it yields on a variable which is called DialogGui. I have used the developer console to see what is nil and what is not. It shows up DialogGui nil. I have a module script in ReplicatedStorage, a LocalScript in StarterCharacterScripts and a ServerScript in a part.

-- Module Script -- 
local data = {}

data.warnScreen = game.ReplicatedStorage.WarnGui
data.backpackScreen = game.ReplicatedStorage.BackpackGui
data.dialogScreen = game.ReplicatedStorage.DialogGui
data.shopBlur = game.ReplicatedStorage.ShopBlur
data.tutorialScreen = game.ReplicatedStorage.TutorialGui
function data.openPageFunction(obj,pageTxt)
    print("Animating Text!")
    for i = 1,#pageTxt do
        obj.Text = string.sub(pageTxt,1,i)
        wait()
    end
end
function data.closePageFunction(obj,pageText)
    print("Animating Text")
    for i = #pageText,1,-1 do
        obj.Text = string.sub(pageText,-1,i)
        wait()
    end
end
function data.openWarning(parent,screen)
    --[[
        MainWarn Old Position: 0, 0,0.824, 0
        MainWarn New Position: 0.004, 0,1.024, 0
        KeyWarn Old Position: 0.423, 0,0.849, 0
        KeyWarn New Position: 0.427, 0,1.048, 0
    --]]
    print("Warning Open!")
    local newWarn = screen:Clone()
    local mainWarn = newWarn:WaitForChild("MainWarn")
    local keyWarn = newWarn:WaitForChild("KeyWarn")
    newWarn.Parent = parent
    mainWarn:TweenPosition(UDim2.new(0, 0,0.824, 0),"Out","Quad",1,true)
    keyWarn:TweenPosition(UDim2.new(0.423, 0,0.849, 0),"Out","Quad",1,true)
end
function data.closeWarning(screen)
    print("Warning Closed!")
    local mainWarn = screen:WaitForChild("MainWarn")
    local keyWarn = screen:WaitForChild("KeyWarn")
    mainWarn:TweenPosition(UDim2.new(0.004, 0,1.024, 0),"Out","Quad",1,true)
    keyWarn:TweenPosition(UDim2.new(0.427, 0,1.048, 0),"Out","Quad",1,true)
end
function data.changeProp(obj,walk,jump)
    obj.WalkSpeed = walk
    obj.JumpPower = jump
end
return data

-- Server Script -- 
local part = script.Parent
local module = require(game.ReplicatedStorage.GameModule)
local page1 = part["Pages_Config"]:WaitForChild("Page1")
local debounce = false
part.Touched:Connect(function(hit)
    print("Part Touched!")
    if debounce == false and hit then
        debounce = true
        print("Debounce to " .. tostring(debounce))
        print("Declaring variables!")
        local hum = hit.Parent:WaitForChild("Humanoid")
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local playerUI = player:FindFirstChild("PlayerGui")
        if player then
            print("Player is not nil!")
        else
            print("Player is nil!")
        end     
        if playerUI then
            print("PlayerGui is not nil!")
        else
            print("PlayerGui is nil!")
        end
        print("Changing humanoid properties!")
        module.changeProp(hum,0,0)
        print("Changed humanoid properties!")
        print("Opening Warning Screen!")
        module.openWarning(playerUI,module.warnScreen)
        print("Opened Warning Screen!")
        print("Declaring variables!")
        local dialogGui = playerUI:WaitForChild(module.dialogScreen.Name)
        if dialogGui then
            print("Dialog Gui not nil!")
        else
            print("Dialog Gui is nil!")
        end
        local frame = dialogGui:WaitForChild("DialogMain")
        local desc = frame:WaitForChild("Desc")
        print("Declared variables!")
        print("Opening page!")
        module.openPageFunction(desc,page1.Value)
        print("Opened page!")
    end
    wait(1)
    if debounce == true then
        debounce = false
    end
end)
-- Local Script --
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local playerUI = player:FindFirstChild("PlayerGui")
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local module = require(game.ReplicatedStorage.GameModule)
uis.InputBegan:Connect(function(key,gpe)
    if key.KeyCode == Enum.KeyCode.X and not gpe and        
               playerUI:FindFirstChild("WarnGui") then
           print("Start Dialog!")
           local newDialog = module.dialogScreen:Clone()
           newDialog.Parent = playerUI 
           local desc = newDialog:WaitForChild("DialogMain"):WaitForChild("Desc") 
           module.closeWarning(playerUI.WarnGui)
           wait(1)                  
           playerUI:WaitForChild("WarnGui"):Destroy()               
    end         
end)

Filtering Enabled is true by the way

2 answers

Log in to vote
0
Answered by 6 years ago

Hello! I think that your problem is that since your game is FilteringEnabled, the server can't see the contents inside of any player's Backpack, StarterGear, or PlayerGui. To fix this, you will want to use a RemoteEvent to FireClient() to the player whose character touched. Then in a LocalScript, call the ModuleScript functions.

-- Line 14 in your script
<RemoteEvent>:FireClient(player)
-- LocalScript
<RemoteEvent>.OnClientEvent:Connect(function()
    -- Call Module functions
end)
0
It might work, however I don't want to give too much power to the client when the game comes out (I mean a lot of dialog systems).Plus I don't want any hackers changing what is inside the system(since the client can't access the server) saSlol2436 716 — 6y
Ad
Log in to vote
-3
Answered by
popeeyy 493 Moderation Voter
6 years ago
Edited 6 years ago

Your name "module" could be mixing up the script. Also, you don't need wait for child. You should just map out the children normally. If it's in PlayerGui try changing the name "Module" as it can confuse the script with the module on line 3. If it's in PlayerGui try local dialogGui = playerUI.module.dialogScreen.Name and change the name of "module". Otherwise, do local dialogGui = module.dialogScreen.Name if you're referring to the module inside ReplicatedStorage defined on line 3. Try not to use WaitForChild when it's not needed and mix up the names.

0
My module name is GameModule and the the table inside the module is named data. Plus I use WaitForChild because not everything loads automaticly, when using dot notation and the object did not load, it would show nil saSlol2436 716 — 6y
0
Learn lua poppey. Its why your rep is low. H4X0MSYT 536 — 6y

Answer this question