I am trying to make a player equip a hat when they join if their hat purchased variable is true.
Part of my saving and loading script.
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder", player) --Creating variables
folder.Name = "leaderstats"
local folder2 = Instance.new("Folder", player)
folder2.Name = "variables"
local folder3 = Instance.new("Folder", player)
folder3.Name="purchases"
local val = Instance.new("IntValue",folder)
val.Name = "Cash"
local val2 = Instance.new("IntValue",folder2)
val2.Name = "PPC"
local val3 = Instance.new("IntValue",folder2)
val3.Name = "CPS"
local val4 = Instance.new("IntValue",folder2)
val4.Name = "Price"
local val5 = Instance.new("IntValue",folder2)
val5.Name = "CPSPrice"
local val6 = Instance.new("BoolValue",folder3)
val6.Name = "TopHat"
local stats = ds:GetAsync(player.UserId)
if stats ~= nil then
val.Value = stats[1]--The numbers are the table below
val2.Value = stats[2]
val3.Value = stats[3]
val4.Value = stats[4]
val5.Value = stats[5]
val6.Value = stats[6]
else
val.Value = 0
val2.Value = 1
val3.Value = 0
val4.Value = 10
val5.Value = 500
val6.Value = false
end
This is what I tried in a separate script This prints No Hat
game.Players.PlayerAdded:Connect(function(player)
local purchases = player:WaitForChild("purchases")
local TopHat = purchases:WaitForChild("TopHat")
if TopHat.Value == true then
local pmodel = player.Character
local hum = pmodel:WaitForChild("Humanoid")
local ss = game:GetService("ServerStorage")
local hat = ss:WaitForChild("TopHat"):Clone()
hum:RemoveAccessories()
hum:AddAccessory(hat)
print("Has hat")
else
print("Has No hat")
end
end)
This is what I tried in the same script as the one that saves and loads It is in player added Doesn't print at all
if player.purchases.TopHat.Value == true then
local pmodel = player.Character
local hum = pmodel:WaitForChild("Humanoid")
local ss = game:GetService("ServerStorage")
local hat = ss:WaitForChild("TopHat"):Clone()
hum:RemoveAccessories()
hum:AddAccessory(hat)
print("Hat")
else
print("No Hat")
end
