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

Is it possible to use module script to change screen gui?

Asked by 3 years ago

I'm new to programming and I am trying to change the screen GUI when another script activating,so here's what I am trying to accomplish.

I first coded a program for my character to dash, and what I imagine is when my character dash,it will change the size of the screen GUI. Here's the program of my dash.

local plr = game.Players.LocalPlayer
local Char = plr.Character 
local UserInputService = game:GetService("UserInputService")
local ATapping= false

local ADcd = false

local module = require(game.StarterGui.ScreenGui["Energy(Back)"].EnergyBar.ModuleCostEnergy)


UserInputService.InputBegan:Connect(function(Input, Run)
    if ADcd == false then

        if Run then return end

        if Input.KeyCode == Enum.KeyCode.A then
            if not ATapping then
                ATapping = true
                wait(0.3)
                ATapping = false
            else
                Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.RightVector* -180
                module.myFunc()
                ADcd=true

                wait(1)
                print("A dash cd done")
                ADcd = false
            end
        end
    end

After that I also coded a module script and put it under the screen gui

local barsize = 100
local cost = 20

local module = {}

module.myFunc = function()
    barsize = barsize - cost
    print(barsize)
    script.Parent:TweenSize(UDim2.new(barsize,0,0,26),"Out","Quint",0.25)
    --test it the module works
    print("testing if it works")
end

return module

And here's the problem,I put a print("testing if it works") and print(barsize) to see if the module script did run when the dash program activated and it does print out ,but it seems not affecting the screen gui,so what went wrong? is it because module script can not affect screen gui but local script can? If so how should I fix it? Thank you.

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

at line 8... Just change

local module = require(game.StarterGui.ScreenGui["Energy(Back)"].EnergyBar.ModuleCostEnergy)

to

local module = require(plr.PlayerGui.ScreenGui["Energy(Back)"].EnergyBar.ModuleCostEnergy)

because the GUIs that are inside StarterGui gets transferred to PlayerGui

P.S I'm sorry if I didn't really did a great job explaining!

Edit: This is a common mistake people do. Even I did this once. But what is happening is that you're NOT seeing the things inside StarterGui, but in your own Gui Folder called PlayerGui. Every player has this (I hope this explanation is clearer)

1
I knew I was just making some dumb mistakes and I already spend around 2 hours trying to figure out, Thank you so much! chronusq 3 — 3y
0
You're welcome! And don't worry, it happens... a lot TheBigBro122 427 — 3y
Ad

Answer this question