Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"gun1string is not a valid member of Folder?"

Hi, when I leave the game, it says that my String is not a valid member of a folder. It's used for a datastore.

Here is all related code.

local gun1 = DataStore:GetDataStore("gun1")

game.Players.PlayerAdded:Connect(function(player)

local parent = Instance.new("Folder")
	parent.Name = "PlayerGuns"
	parent.Parent = player

local gun1string = Instance.new("StringValue")
	gun1string.Name = "Gun1"
	gun1string.Value = gun1:GetAsync(player.userId) or "startergun1"
	gun1string.Parent = parent

end) 


game.Players.PlayerRemoving:Connect(function(player)
	gun1:SetAsync(player.userId, player.PlayerGuns.gun1string.Value)
end)

1 answer

✓ Accepted answer

Line 1 made the problems. You must change the DataStore to :GetService("DataStore"). This is because DataStore is a service. It is a top-level singleton which can be retrieved using the GetService function. Also, make a 'game' start.

Line 1 correct code :

local gun1 = game.GetService("DataStore"):GetDataStore("gun1")

Line 3,4 make problems too. You might change that Instance.new("Folder") You need to make it line by line.

Line 3 correct code :

local parent = Instance.new("Folder")
Parent.Name = "PlayerGuns"
Parent.Parent = player

Line 4 and line 6 is messy! You can make it line by line too!

Here is the full script :

local gun1 = game.GetService("DataStore"):GetDataStore("gun1")

game.Players.PlayerAdded:Connect(function(player)

local parent = Instance.new("Folder")
Parent.Name = "PlayerGuns" 
Parent.Parent = player

local gun1string = Instance.new("StringValue") 
gun1string.Name = "Gun1" 
gun1string.Value = gun1:GetAsync(player.userId)or "startergun1" gun1string.Parent = parent

end)

Delete last 3 lines because the function of PlayerRemoving that when you leave will cost errors.

Hope I helped, have a nice day. Happy coding ;D

2 comments

0

thanks

0

No problem :D I glad to help peoples :)

This discussion is preserved as it was. New answers, comments, and votes are closed.