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

My script is not doing what it's suppost to do and there are no errors in the output?

Asked by 5 years ago

So pretty much what this script is supposed to do it's supposed to look for a change to an int value when it detects that the int value is set to 150 or more it's supposed to clone the GUI and set it's parent to starter gui. I tested it and it's not cloning or even setting its parent to starter gui. Here is the code:

local Storage = game.Workspace:WaitForChild("Storage1")
local Storage1 = game.Workspace.Storage1
local MaxValue = 150
local Gui = script.Parent.Main.SellGui
if(Storage1.Value >= 150) then
    Gui:Clone()
    Gui.Parent = "StarterGui"
    while true do
        wait()
    end
end

2 answers

Log in to vote
0
Answered by 5 years ago

Found it. Dont clone the gui to StarterGui. Place it to the playergui from the player.

script:

local Storage = game.Workspace:WaitForChild("Storage1")
local Storage1 = game.Workspace.Storage1
local MaxValue = 150
local Gui = script.Parent.Main.SellGui
if(Storage1.Value >= 150) then
    Gui:Clone()
    Gui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
    while true do
        wait()
    end
end

if the script is actually a normal script, please comment on my answer.

0
It's a normal script appleprogamer_59 29 — 5y
0
Where is the script located at? ieatandisbaconhair 77 — 5y
Ad
Log in to vote
0
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

A couple of things wrong with your code, first there is no event listener, meaning that this script will only run once and thats it, even if your Storage1 value changes to more than 150 nothing will happen as the script already ended long before that, you can use the .Changed event so that whenever storage1 value changes, it will check if its more than 150

Secondly, setting the parent of the gui is not done by indicating Strings, you have to indicate the parent as an object. Ill show you what i mean in the code.

local Storage = game.Workspace:WaitForChild("Storage1")
local Storage1 = game.Workspace.Storage1 -- you dont have to assign the variable twice, the first line already assigns the variable 
local MaxValue = 150
local Gui = script.Parent.Main.SellGui
--add an event listener here
if(Storage1.Value >= 150) then
    Gui:Clone()-- assign this Cloned gui to a variable
    Gui.Parent = "StarterGui"-- this wont work
    while true do
        wait()
    end
end

Also i am not sure if you know this but you should put the gui into playerGuis instead if you want the player to see the gui immediately, Startergui only works when the player joins the game, or respawns

local Storage = game.Workspace:WaitForChild("Storage1")
local MaxValue = 150
local Gui = script.Parent.Main.SellGui
Storage.Changed:Connect(function()
if(Storage1.Value >= 150) then
    local ClonedGUI = Gui:Clone()
    ClonedGUI.Parent = game.StarterGui--the player will only see the gui when he respawns 
    while true do
        wait()
    end
end
end()

Answer this question