This is a second part on one of my topics, ‘How do I weld boots to the players legs? (r6)’ My issue is that I’ve been working on a simple boot switching system for developers. The cloned boots only appear when the player’s character loads in again. Not even when the selected boots value is changed! This topic also fits in the Code Review category.
My entire code :
local DataStoreService = game:GetService('DataStoreService')
local DataBase = DataStoreService:GetDataStore("PlayerBase4")
local data = {}
game.Players.PlayerAdded:Connect(function(player)
local success, playerData
success, playerData = pcall(function()
return DataBase:GetAsync(player.UserId)
end)
if success then
if not playerData then
playerData = {
["SelectedBoots"] = "Default",
}
end
data[player.UserId] = playerData
end
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local height = Instance.new("NumberValue", leaderstats)
height.Name = "Height"
local selectedBoots = Instance.new("StringValue", player)
selectedBoots.Name = "SelectedBoots"
selectedBoots.Value = playerData.SelectedBoots
player.CharacterAdded:Connect(function(character)
local leftBoot = game:GetService('ReplicatedStorage'):WaitForChild("Boots"):FindFirstChild(selectedBoots.Value):Clone()
leftBoot:SetPrimaryPartCFrame(character["Left Leg"].CFrame * CFrame.new(0,-.6,0) * CFrame.Angles(0,math.rad(270),0))
leftBoot.Parent = character
leftBoot.WeldConstraint.Part0 = leftBoot.PrimaryPart
leftBoot.WeldConstraint.Part1 = character["Left Leg"]
leftBoot.Name = "LeftBoot"
local rightBoot = game:GetService('ReplicatedStorage'):WaitForChild("Boots"):FindFirstChild(selectedBoots.Value):Clone()
rightBoot:SetPrimaryPartCFrame(character["Right Leg"].CFrame * CFrame.new(0,-.6,0) * CFrame.Angles(0,math.rad(270),0))
rightBoot.Parent = character
rightBoot.WeldConstraint.Part0 = rightBoot.PrimaryPart
rightBoot.WeldConstraint.Part1 = character["Right Leg"]
rightBoot.Name = "RightBoot"
selectedBoots.Changed:Connect(function()
data[player.UserId].SelectedBoots = selectedBoots.Value
if character:FindFirstChild("LeftBoot") then
character:FindFirstChild("LeftBoot"):Destroy()
end
if character:FindFirstChild("RightBoot") then
character:FindFirstChild("RightBoot"):Destroy()
end
local leftBoot2 = game:GetService('ReplicatedStorage'):WaitForChild("Boots"):FindFirstChild(selectedBoots.Value):Clone()
leftBoot2:SetPrimaryPartCFrame(character["Left Leg"].CFrame * CFrame.new(0,-.6,0) * CFrame.Angles(0,math.rad(270),0))
leftBoot2.Parent = character
leftBoot2.WeldConstraint.Part0 = leftBoot2.PrimaryPart
leftBoot2.WeldConstraint.Part1 = character["Left Leg"]
leftBoot2.Name = "LeftBoot"
local rightBoot2 = game:GetService('ReplicatedStorage'):WaitForChild("Boots"):FindFirstChild(selectedBoots.Value):Clone()
rightBoot2:SetPrimaryPartCFrame(character["Right Leg"].CFrame * CFrame.new(0,-.6,0) * CFrame.Angles(0,math.rad(270),0))
rightBoot2.Parent = character
rightBoot2.WeldConstraint.Part0 = rightBoot2.PrimaryPart
rightBoot2.WeldConstraint.Part1 = character["Right Leg"]
rightBoot2.Name = "RightBoot"
end)
while wait() do
local humanoidPart = character:WaitForChild("HumanoidRootPart") or character:WaitForChild("Torso")
if humanoidPart then
height.Value = math.round(humanoidPart.Position.Y / 3)
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, playerData
success, playerData = pcall(function()
return DataBase:SetAsync(player.UserId, data[player.UserId])
end)
end)