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)

10 comments
If Fruit is a NumberValue, you'll want to change line 11 to be 'if Fruit.Value == 1 then', with no parentheses around the 1
Otherwise if it's a StringValue, then instead of printing "hey" on line 10, print Fruit.Value to see what value it actually is
i tried that and it doesnt work
Did you try what I wrote in my second comment? If Fruit.Value isn't "1", what is it?
it equals 0
Shouldn’t it be HasFruit.Value == false?
nope, its supposed to be HasFruit.Value == true but that doesnt work.
You wrote “not” which flips HasFruit.Value, remove the operator to ensure the logic stays direct.
okay, so now i did if HasFruit.Value == false then print("no fruit") else print("Has Fruit") if Fruit.Value == 1 then print("Give Ice") and it still doesnt work
when i tell it to print the Fruit's value, it always outputs "0". Although, my player's fruit value is 1.