this code is supposed to give the "iceFruit" to the player IF they have the value "1". however, the code doesn't advance past where it outputs "hey". is it a problem with the second if statement? and how would i fix it?
UPDATE: SOLUTION HAS BEEN FOUND, THANKS FOR EVERYONE'S EFFORTS.
local Players = game:GetService("Players") local RS = game:GetService("ReplicatedStorage") local function onPlayerAdded(player) local iceFruit = RS.DFs:FindFirstChild("Ice_Moves"):Clone() local Fruit = player:WaitForChild("OtherValues"):FindFirstChild("Fruit") local function onCharacterAdded(character) if player.OtherValues.HasFruit == false then print("No fruit given") else print("Has fruit") print(Fruit.Value) if Fruit.Value == 1 then print("ice given") iceFruit.Parent = player.Backpack end end end if player.Character then onCharacterAdded(player.Character) end player.CharacterAdded:Connect(onCharacterAdded) end for i, player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end Players.PlayerAdded:Connect(onPlayerAdded)
this is the code where the value is given:
-- Data Service local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") game.Players.PlayerAdded:Connect(function(player) local GameValues = Instance.new("Folder") GameValues.Name = "GameValues" GameValues.Parent = player local OtherValues = Instance.new("Folder") OtherValues.Name = "OtherValues" OtherValues.Parent = player local HasFruit = Instance.new("BoolValue") HasFruit.Name = "HasFruit" HasFruit.Parent = OtherValues local fruit = Instance.new("NumberValue") fruit.Name = "Fruit" fruit.Parent = OtherValues --data save local data, data2 local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId.."-HasFruit",player.OtherValues.HasFruit.Value) data2 = myDataStore:GetAsync(player.UserId.."-fruit",player.OtherValues.Fruit.Value) end) if success then HasFruit.Value = data fruit.Value = data2 print("Data loaded!") else print("There was an error loading data.") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId.."-HasFruit",player.OtherValues.HasFruit.Value) myDataStore:SetAsync(player.UserId.."-fruit",player.OtherValues.Fruit.Value) end) if success then print ("Save success!") else print ("There was an error saving.") warn(errormessage) end end)
-- Data Service local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") game.Players.PlayerAdded:Connect(function(player) local GameValues = Instance.new("Folder") GameValues.Name = "GameValues" GameValues.Parent = player local OtherValues = Instance.new("Folder") OtherValues.Name = "OtherValues" OtherValues.Parent = player local HasFruit = Instance.new("BoolValue") HasFruit.Name = "HasFruit" HasFruit.Parent = OtherValues local fruit = Instance.new("NumberValue") fruit.Name = "Fruit" fruit.Parent = OtherValues --data save local data, data2 local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId.."-HasFruit")--u just copy and pasted the setasync but changed setasync to getasync data2 = myDataStore:GetAsync(player.UserId.."-fruit") --your only supposed to give the string end) if success then HasFruit.Value = data fruit.Value = data2 print("Data loaded!") else print("There was an error loading data.") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId.."-HasFruit",player.OtherValues.HasFruit.Value) myDataStore:SetAsync(player.UserId.."-fruit",player.OtherValues.Fruit.Value) end) if success then print ("Save success!") else print ("There was an error saving.") warn(errormessage) end end)