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

"gun1string is not a valid member of Folder?"

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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

0
thanks lachdoghotdog 2 — 4y
0
No problem :D I glad to help peoples :) Xapelize 2658 — 4y
Ad

Answer this question