I have a script where you select a map, but then when you close the menu you have to load the map again.
I have the current map that was selected by the player stored in a StringValue inside PlayerScripts.
How would I make it clone?
I tried doing SelectedTheme:Clone()
but that doesnt work because it thinks I mean the thing I want to clone is called SelectedTheme.
Here is the script basically (just without the rest of the actual inventory stuff cause its ALOT and its really not needed for this)
local CurrentTheme = game.Workspace.CurrentTheme
local SelectedTheme = game.Players.LocalPlayer.PlayerScripts.SelectedMap.Value
CurrentTheme:ClearAllChildren()
ThemeFolder.Grass:Clone().Parent = game.Workspace.CurrentTheme --error caused here
script.Parent.Text = "Inventory"
Error :
Players.eggspIicit.PlayerGui.Main.InventoryPlace.Inventory.InventoryMain:42: attempt to call a nil value
EDIT #1
I changed it to this because I thought it might work, but instead I just got this error shown below.
CurrentTheme:ClearAllChildren()
ThemeFolder.(SelectedTheme.Value):Clone().Parent = game.Workspace.CurrentTheme
script.Parent.Text = "Inventory"
Players.eggspIicit.PlayerGui.Main.InventoryPlace.Inventory.InventoryMain:42: Expected identifier, got â(â
EDIT #2
Tried changing it to this, and also got another error, which is of course. Shown below.
CurrentTheme:ClearAllChildren()
ThemeFolder:WaitForChild(SelectedTheme.Value):Clone().Parent = game.Workspace.CurrentTheme
script.Parent.Text = "Inventory"
Argument 1 missing or nil
sorry if this is worded bad, im not sure how to word this, please ask if u need better explanation
The value from a stringvalue is a string, not an instance. This means you cannot clone it. (I think)
If you want to move the value to somewhere else, you could add a stringvalue to your second object, and set itâs value to the first stringvalueâs value.
Can you explain this part a little better, Iâm a little confused sorry
If you mean to clone the StringValue instance, it isnt working because itâs trying to clone a property.
local SelectedTheme = game.Players.LocalPlayer.PlayerScripts.SelectedMap.Value
for it to work it should be:
local SelectedTheme = game.Players.LocalPlayer.PlayerScripts.SelectedMap
Sure, but is currenttheme a stringvalue or something else?
No, Iâm trying to get the value because the value is the actual name of the map they selected
The current theme is the folder, the string value is called SelectedTheme
Why would you need to clone this? Just get the value, once you use it itâll still be able to be used again!
If you want to clone the stringvalue to that folder, then do it without the .value
If you just want to get the value, then just use .value
Its hard for me to explain but basically when the player selects the map in the inventory menu, it sets the value then when the player closes the inventory menu, the map should appear there.
BUT
Since there are multiple maps I canât just set it to Grass
(script below) for example (Grass & Lab are the two maps) because if the player has Lab
selected then it wont show, it will come up with the Grass
.
CurrentTheme:ClearAllChildren()
ThemeFolder.Grass:Clone().Parent = game.Workspace.CurrentTheme
script.Parent.Text = "Inventory"
But I want it to be the map which is in the value for the stringvalue
I will record a short video real quick to see if that can help explain it.
EDIT VIDEO
As yo can see in the video, the map just completely disappears as there is no map called âSelectedThemeâ. Even though SelectedTheme is actually just the variable ( i think) of what im trying to clone.
Hence it being
local SelectedTheme = game.Players.LocalPlayer.PlayerScripts.SelectedMap.Value
edit video broke
video link here
and reply to
No, they are not. The folder where they are held is called âCurrentThemeâ and it clears whenever a new map is loaded.
Are both of the maps in workspace at all times?
Wouldnât it be easier to detect if the value changed, and then load the map based on what the new value is?
I mean, I guess but I also wanna keep it so just when the button is pressed it changes
Canât you change the value from the button though?
The value does get changed from the button, these two.
This is the script inside them (Just changing from Grass to Lab, vise versa)
local ThemeFolder = game.ReplicatedStorage.Themes
local CurrentTheme = game.Workspace.CurrentTheme
script.Parent.MouseButton1Click:Connect(function()
CurrentTheme:ClearAllChildren()
ThemeFolder.Lab:Clone().Parent = game.Workspace.CurrentTheme
game.Players.LocalPlayer.PlayerScripts.SelectedMap.Value = "Lab"
end)
Katrist
(Katrist)
July 15, 2022, 9:53pm
#16
Whatâs the code for the close button?
If you wanna see the whole script that handles open and closing the inventory, this is it.
added annotations as i wrote if that helps
--// Showing Inventory Button Position 0.872, 0,0.473, 0
--// Hiding Inventory Button Position 1.872, 0,0.473, 0
local ThemeFolder = game.ReplicatedStorage.Themes
local CurrentTheme = game.Workspace.CurrentTheme
local MainUis = script.Parent.Parent.Parent.ClickerAndThemePicker
local InventoryFrame = script.Parent.Parent.InventoryFrame
local ShopFrame = script.Parent.Parent.Parent.ShopPlace.ShopFrame
local toggled = true
local SelectedTheme = game.Players.LocalPlayer.PlayerScripts.SelectedMap.Value
script.Parent.MouseButton1Click:Connect(function()
--// Set new map in
CurrentTheme:ClearAllChildren()
ThemeFolder.Shop:Clone().Parent = game.Workspace.CurrentTheme
if toggled == true then
toggled = false
--// Tween Shop Button for glitch-proof idea ( WIP )
ShopFrame.Parent.OpenShop:TweenPosition(UDim2.new(1.873, 0,0.414, 0), 0.5, "Linear")
--// Hide Other GUIS
MainUis.Visible = false
ShopFrame.Visible = false
InventoryFrame.Visible = true
--// Change text & toggle status
script.Parent.Text = "Close"
else if toggled == false then
toggled = true
--// Tween Shop Button for glitch-proof idea ( WIP )
ShopFrame.Parent.OpenShop:TweenPosition(UDim2.new(0.873, 0,0.414, 0), 0.5, "Linear")
--// Add back GUIS
MainUis.Visible = true
ShopFrame.Visible = false
InventoryFrame.Visible = false
--// Change text & toggle status & Set back map
CurrentTheme:ClearAllChildren()
ThemeFolder.SelectedTheme:Clone().Parent = game.Workspace.CurrentTheme
script.Parent.Text = "Inventory"
end
end
end)
Katrist
(Katrist)
July 15, 2022, 10:00pm
#18
Try this:
--// Showing Inventory Button Position 0.872, 0,0.473, 0
--// Hiding Inventory Button Position 1.872, 0,0.473, 0
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local LocalPlayer = Players.LocalPlayer
local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")
local ThemeFolder = ReplicatedStorage.Themes
local CurrentTheme = workspace.CurrentTheme
local Button = script.Parent
local MainUis = Button.Parent.Parent.ClickerAndThemePicker
local InventoryFrame = Button.Parent.InventoryFrame
local ShopFrame = Button.Parent.Parent.ShopPlace.ShopFrame
--//Controls
local toggled = false
--//Functions
Button.MouseButton1Click:Connect(function()
toggled = not toggled
if toggled then
--// Tween Shop Button for glitch-proof idea ( WIP )
ShopFrame.Parent.OpenShop:TweenPosition(UDim2.new(1.873, 0,0.414, 0), 0.5, Enum.EasingStyle.Linear)
--// Hide Other GUIS
MainUis.Visible = false
ShopFrame.Visible = false
InventoryFrame.Visible = true
--// Change text & toggle status
Button.Text = "Close"
else
--// Tween Shop Button for glitch-proof idea ( WIP )
ShopFrame.Parent.OpenShop:TweenPosition(UDim2.new(0.873, 0,0.414, 0), 0.5, Enum.EasingStyle.Linear)
--// Add back GUIS
MainUis.Visible = true
ShopFrame.Visible = false
InventoryFrame.Visible = false
--// Change text & toggle status & Set back map
CurrentTheme:ClearAllChildren()
ThemeFolder.SelectedTheme:Clone().Parent = CurrentTheme
Button.Text = "Inventory"
end
end)
This script doesnt bring up the shop map ( which is this â ThemeFolder.Shop:Clone().Parent = game.Workspace.CurrentTheme
)
Aswell with this error, same as last time with the other scriptâŚ
SelectedTheme is not a valid member of Folder âReplicatedStorage.Themesâ
Which is what I had in the first post on this thread.
Katrist
(Katrist)
July 15, 2022, 10:08pm
#20
Oh okay, try this:
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local LocalPlayer = Players.LocalPlayer
local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts")
local SelectedTheme = PlayerScripts.SelectedMap
local ThemeFolder = ReplicatedStorage.Themes
local CurrentTheme = workspace.CurrentTheme
local Button = script.Parent
local MainUis = Button.Parent.Parent.ClickerAndThemePicker
local InventoryFrame = Button.Parent.InventoryFrame
local ShopFrame = Button.Parent.Parent.ShopPlace.ShopFrame
--//Controls
local toggled = false
--//Functions
Button.MouseButton1Click:Connect(function()
toggled = not toggled
if toggled then
CurrentTheme:ClearAllChildren()
ThemeFolder.Shop:Clone().Parent = CurrentTheme
--// Tween Shop Button for glitch-proof idea ( WIP )
ShopFrame.Parent.OpenShop:TweenPosition(UDim2.new(1.873, 0,0.414, 0), 0.5, Enum.EasingStyle.Linear)
--// Hide Other GUIS
MainUis.Visible = false
ShopFrame.Visible = false
InventoryFrame.Visible = true
--// Change text & toggle status
Button.Text = "Close"
else
--// Tween Shop Button for glitch-proof idea ( WIP )
ShopFrame.Parent.OpenShop:TweenPosition(UDim2.new(0.873, 0,0.414, 0), 0.5, Enum.EasingStyle.Linear)
--// Add back GUIS
MainUis.Visible = true
ShopFrame.Visible = false
InventoryFrame.Visible = false
--// Change text & toggle status & Set back map
print(SelectedTheme.Value)
CurrentTheme:ClearAllChildren()
ThemeFolder:WaitForChild(SelectedTheme.Value):Clone().Parent = CurrentTheme
Button.Text = "Inventory"
end
end)
Tell me if it prints anything.
1 Like