What do you want to achieve? I would like to work on a item saving system. I am likely going about it wrong.
What is the issue? This script is not getting past my if statements.
What solutions have you tried so far? I have searched, and have failed to find anything like this.
Here is my script:
game.Players.PlayerAdded:Connect(function(plr)
local ServerStorage = game:GetService("ServerStorage")
local ownedtools = plr:WaitForChild("SavedTools")
print("player loaded")
if ownedtools.powerUp.Value then
ServerStorage:WaitForChild("SuperPower"):Clone().Parent = plr:WaitForChild("Backpack")
ServerStorage:WaitForChild("SuperPower"):Clone().Parent = plr:WaitForChild("OwnedTools")
print("got past if, should have loaded items")
end
end)
Upon my testing; It got past the if statement but the issue seems to be something with ServerStorage:WaitForChild because it doesn’t even print a error for me that I don’t have it. I’ll do some further testing but I want to make it apparent to you before I do more testing.
game.Players.PlayerAdded:Connect(function(plr)
--script.SavedTools.Parent = plr
local ServerStorage = game:GetService("ServerStorage")
local ownedtools = plr:WaitForChild("SavedTools")
print("player loaded")
if ownedtools.powerUp.Value then
warn('got here')
ServerStorage:WaitForChild("SuperPower"):Clone().Parent = plr:WaitForChild("Backpack")
ServerStorage:WaitForChild("SuperPower"):Clone().Parent = plr:WaitForChild("OwnedTools")
print("got past if, should have loaded items")
end
end)
I added a print right after the if and it prints for me, seems as if the clone is the issue. Attempting a fix now
game.Players.PlayerAdded:Connect(function(plr)
local ServerStorage = game:GetService("ServerStorage")
local ownedtools = plr:WaitForChild("SavedTools")
print("player loaded")
if ownedtools.powerUp.Value then
warn('got here')
ServerStorage:WaitForChild("SuperPower"):Clone().Parent = plr:WaitForChild("Backpack")
ServerStorage:WaitForChild("SuperPower"):Clone().Parent = ownedtools
print("got past if, should have loaded items")
end
end)
We have a folder inside of the player called SavedTools. If the player owns this the value is true. If the value is true then we are cloning “SuperPower” to the Backpack and another folder in the player called “OwnedTools”.
local ServerStorage = game:GetService("ServerStorage")
local ownedtools = plr:WaitForChild("SavedTools")
print("player loaded")
if ownedtools.powerUp.Value then
ServerStorage:WaitForChild("SuperPower"):Clone().Parent = plr:WaitForChild("Backpack")
ServerStorage:WaitForChild("SuperPower"):Clone().Parent = plr:WaitForChild("OwnedTools")
warn("got past if, should have loaded items")
end
This should be your exact code and I effectively get to the “got past if” as shown below
To add; Look over my initialization and make sure it matches yours