Datastore won't work?

I only mentioned it twice, but here is the code for it:

local Players = game:GetService("Players")
local Player = game:GetService("Players").LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Statue = workspace.Statue.Char

local Players = game:GetService("Players")
local Player = game:GetService("Players").LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Statue = workspace.Statue.Char -- Assuming "Statue" is a Model in the workspace

-- Player Item Functions

function Accessory(v, Material, Color) -- Accessory Function
	local Handle = v:FindFirstChildWhichIsA("MeshPart")
	
	Handle.TextureID = ""
	Handle.Material = Material
	Handle.Color = Color
end

function MeshPart(v, Material, Color) -- Part Function
	v.Material = Material
	v.Color = Color
end

function BaseAppearance(Morph, MorphHumanoid, Scale, Material, Color)
	MorphHumanoid:WaitForChild("BodyHeightScale").Value *= Scale
	MorphHumanoid:WaitForChild("BodyDepthScale").Value *= Scale
	MorphHumanoid:WaitForChild("BodyWidthScale").Value *= Scale
	MorphHumanoid:WaitForChild("HeadScale").Value *= Scale
	
	for i, v in pairs(Morph:GetChildren()) do
		if v:IsA("Pants") then
			v.PantsTemplate = ""
		elseif v:IsA("Shirt") then
			v.ShirtTemplate = ""
		elseif v:IsA("ShirtGraphic") then
			v:Destroy()
		elseif v:IsA("Accessory") then
			Accessory(v, Material, Color)
		elseif v:IsA("MeshPart") then
			MeshPart(v, Material, Color)
		end
	end
	
	MorphHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end
function StatueAppearance()
	-- Variables
	
	Character.Archivable = true
	local CharacterMorph = Character:Clone()
	local MorphHumanoid = CharacterMorph:WaitForChild("Humanoid")
	-- Statue Body Appearance Variables
	
	local Player_Material = Player:WaitForChild("Material").Value
	local Scale = 15
	local Material = Enum.Material[Player_Material]
	local Color = Color3.new(Player:WaitForChild(R.Value, Player.G.Value, Player.B.Value))
	-- Statue Position
	
	CharacterMorph:SetPrimaryPartCFrame(Statue.PrimaryPart.CFrame) -- Set the character's position to match the Statue's position
	-- Revert the statue to normal and set all the changes
	
	Statue:ClearAllChildren()
	CharacterMorph.Parent = Statue
	BaseAppearance(CharacterMorph, MorphHumanoid, Scale, Material, Color)
	Character.Archivable = false
end

StatueAppearance()

Well it looks fine to me.

Does the script I gave work for you?

Yes it did *charss ijweofjqweofjqwoefjqwei

Awesome! I am glad I got you somewhere!

It is hard to find the issue cuz we don’t know how did you built your game.

Well I mean but it’s really scuffed and it caused a few bugs. And by a few I mean a single bug–it says CorrodedMetal is not a member of Enum.Material. Thanks for pretty much writing my entire code though.

it was a tostring value. Make sure to turn it into a Enum

I’m confuzzled. It worked before when I did string value and Enum.Material[String] but now it doesn’t when I do startvalue = “CorrodedMetal”.

Would I do type = enum? 30000000

Here’s a method to turn a string into a Enum

local function stringToEnum(enumType, stringValue)
	local enumItems = Enum[enumType]:GetEnumItems()

	for _, enumItem in ipairs(enumItems) do
		if enumItem.Name == stringValue then
			return enumItem
		end
	end

	return nil
end

local enumType = "Material"
local stringValue = "Plastic"
-- Enum.Material.Plastic
local enumItem = stringToEnum(enumType, stringValue)
if enumItem then
	print("Enum item found:", enumItem.Name, enumItem.Value)
else
	print("No matching Enum item found.")
end

Couldn’t I just turn it into a string and then do Enum.Material[Material], though?

I mean. yeah that works. here’s a method just in case

local function stringToEnum(enumType, stringValue)
    local enum = Enum[enumType]

    if enum then
        return enum[stringValue]
    end

    return nil
end

I’m sorry but I’m stupid–where would I put that function and use it?

You put it in the ServerScript and where the Material check happens convert the string into a Enum

I did it like this:

local function stringToEnum(enumType, stringValue)
	local enum = Enum[enumType]

	if enum then
		return enum[stringValue]
	end

	return nil
end

local StatsTable = {
	["Money"] = {
		Type = "IntValue",
		StartValue = 0,
		Parent = "leaderstats"
	},
	["Fans"] = {
		Type = "IntValue",
		StartValue = 0,
		Parent = "leaderstats"
	},
	["Color"] = {
		Type = "Color3Value",
		StartValue = Color3.fromRGB(255, 255, 255),
		Parent = "leaderstats"
	},
	["Material"] = {
		Type = "Material",
		StartValue = "CorrodedMetal",
		Parent = "leaderstats"
	},
		stringToEnum("Material", "CorrodedMetal") 
}

and it says:

  19:46:39.460  Type is not a valid member of "Enum.Material.CorrodedMetal"  -  Server - ModuleScript:26

this is modulescript:

local StatsHandler = {}

function StatsHandler.AddInstance(Path,InstanceType,Value,Name)

	local SunkistOrange = Instance.new(InstanceType,Path)

	SunkistOrange.Name = Name

	if (InstanceType == "Folder") then

		return SunkistOrange

	end

	SunkistOrange.Value = Value

	return SunkistOrange

end


function StatsHandler.AddFromTable(Table,Player)
	local Sun = {}
	for Name,EachStat in Table do

		local a = Instance.new(EachStat["Type"],Player:FindFirstChild(EachStat["Parent"]))

		a.Name = Name

		a.Value = EachStat["StartValue"]

		table.insert(Sun, a)

	end
	return Sun
end

return StatsHandler

No, you should call the method in the PlayerAdded event handler where the material is actually applied to the saved value.

1 Like

now it says:

  20:27:39.801  Unable to create an Instance of type "Material"  -  Server - ModuleScript:26

I just realised I have a much easier way to do all this and sorry for wasting your time you deserve like 10 solutions but here is your well deserved solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.