You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Im trying to make it save what gender you chose ingame -
What is the issue? Include screenshots / videos if possible!
It changes the characters gender but doesnt save in the datastore
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("skinChange")
local genderEvent = game:GetService("ReplicatedStorage"):WaitForChild("genderChange")
local girlHair = game:GetService("ReplicatedStorage"):WaitForChild("GirlHair")
local DataStore2 = require(ServerScriptService.DataStore2)
DataStore2.Combine("DATA", "gender")
Players.PlayerAdded:Connect(function(player)
local pointsStore = DataStore2("gender", player)
local points = Instance.new("NumberValue")
points.Name = "isGirl"
points.Value = pointsStore:Get(false) -- The "0" means that by default, they'll have 0 points
points.Parent = player
pointsStore:OnUpdate(function(newPoints)
-- This function runs every time the value inside the data store changes.
points.Value = newPoints
end)
player:WaitForChild("Humanoid").Died:Connect(function()
if player:WaitForChild("isGirl").Value == true then
local girlClone = girlHair:Clone()
girlClone.Parent = player
end
end)
end)
remoteEvent.OnServerEvent:Connect(function(character, colour)
local bodyColours = character.Character:WaitForChild("Body Colors")
bodyColours.HeadColor = colour
bodyColours.LeftArmColor = colour
bodyColours.RightArmColor = colour
bodyColours.LeftLegColor = colour
bodyColours.RightLegColor = colour
bodyColours.TorsoColor = colour
end)
genderEvent.OnServerEvent:Connect(function(character, gender)
local pointsStore = DataStore2("gender", character)
if gender == "boy" then
character.Character:WaitForChild("GirlHair"):Destroy()
pointsStore:Set(false)
else
local hairClone = game:GetService("ReplicatedStorage"):WaitForChild("GirlHair"):Clone()
hairClone.Parent = character.Character
pointsStore:Set(true)
end
end)