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

Gui isnt working?

Asked by
Spoookd 32
8 years ago

I am trying to spawn maps in when there are two or more players in the game. When the map is chosen, a gui will pop up displaying the map, map name and who made it. This is the Local Script, but the server script for everything else can be found here: https://scriptinghelpers.org/questions/31040/map-spawning-loop-fix

player = game.Players.LocalPlayer
guis = player.PlayerGui.ScreenGui


for i, v in pairs(game.ServerStorage:GetChildren()) do
    vclone = v:Clone()
    if vclone.Parent == game.Workspace then
        guis.Frame.Madeby.Text = "Made by: Spoookd"
        guis.Frame.MapName.Text = vclone.Name
    end
end

2 answers

Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago

On line 5 you browse through the children of game.ServerStorage but on line 7 you test whether the clone's parent is game.Workspace. A clone is an exact copy of an object, which means the Parent property of the clone will be the same as the original. Since the parent remains the same, vclone.Parent == game.Workspacewill obviously always return false. Thus, the contents of the block is never executed.

0
Our answers sound about the same xD Great answer! User#11440 120 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

There are a few problems with your script.

  • Local Scripts Can't Access ServerStorage.

To fix this, change the script to this, and move everything from ServerStorage to ReplicatedStorage.

local player = game.Players.LocalPlayer
local guis = player.PlayerGui.ScreenGui

for i, v in pairs(game.ReplicatedStorage:GetChildren()) do
    local vclone = v:Clone()
    if vclone.Parent == game.Workspace then
        guis.Frame.Madeby.Text = "Made by: Spoookd"
        guis.Frame.MapName.Text = vclone.Name
    end
end
  • Your checking the parent before defining the parent!

In line 5, you define a variable of the cloned object "v". When making a clone, the parent is nil until defined. So I would suggest, not doing this. I'm unsure of what you're trying to do. But I'm simply getting rid of it.

local player = game.Players.LocalPlayer
local guis = player.PlayerGui.ScreenGui

for i, v in pairs(game.ReplicatedStorage:GetChildren()) do
    local vclone = v:Clone()
    guis.Frame.Madeby.Text = "Made by: Spoookd"
    guis.Frame.MapName.Text = vclone.Name
end

For the record, v's parent will always be ReplicatedStorage because that's where you're getting it.

This might have not have been very helpful, but good luck.

Good Luck!

0
Oh yeah, forgot to mention the fact that it is a localscript. Link150 1355 — 8y

Answer this question