Как создать расы в Роблоксе

Опубликовано: 01 Ноябрь 2024
на канале: Savchenap
617
41

#роблокс #роблокскоды #robloxedit #роблоксгайд
Простой способ создать несколько рас в Roblox Studio

00:12 Создание персонажей
04:32 Настройка команд
06:55 Пользовательский интерфейс (GUI)
11:25 Скрипты

-- кнопка "Раса" -----------------------------------
script.Parent.MouseButton1Click:Connect(function(player)
script.Parent.Parent.Frame.Visible = not script.Parent.Parent.Frame.Visible
end)

----- OrcButtonScript ---------------------------------
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local event1 = ReplicatedStorage.Events:WaitForChild("ChooseRaceEvent")
local event2 = ReplicatedStorage.Events:WaitForChild("SetRaceEvent")
local player = game.Players.LocalPlayer

local teams = game:GetService("Teams")

script.Parent.MouseButton1Click:Connect(function()
event1:FireServer(teams.Orc)
wait(1)
event2:FireServer()
end)


--------------- RaceScript ---------------------------------
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RSE = ReplicatedStorage.Events

local players = game:GetService("Players")
local teams = game:GetService("Teams")

local function ChangeRace(player)
local model = game.ReplicatedStorage.Char:FindFirstChild(player.Team.Name):Clone()
if model then
model.Parent = workspace
model.Name = player.Name
player.Character = model
end
end

RSE.SetRaceEvent.OnServerEvent:Connect(ChangeRace)


local function ChooseRace(player, team)
local DS = game:GetService("DataStoreService")
local RS = DS:GetDataStore("Races") -- таблица для рас

local key = player.userId
player.Team = team
local race = player.Team.Name
-- сохраняем расу
local success, error = pcall(function()
RS:SetAsync(key, race)
end)
end
RSE.ChooseRaceEvent.OnServerEvent:Connect(ChooseRace)


-------------- LeaderScript-----------------------------------
local DS = game:GetService("DataStoreService")
local RS = DS:GetDataStore("Races") -- таблица для рас
local CS = DS:GetDataStore("Coins") -- таблица для монет
local FS = DS:GetDataStore("Stars") -- таблица для фрагов
local players = game:GetService("Players")
local teams = game:GetService("Teams")

local function SaveStat(player)
local key = player.userId
local race = player.Team.Name

local leaderstats = player:FindFirstChild("leaderstats")
local coin = leaderstats.Coins -- берем монеты из лидерстата
local dust = leaderstats.Stars -- берем фрагов из лидерстата

-- сохраняем монеты
local success, error = pcall(function()
CS:SetAsync(key, coin.Value)
end)

-- сохраняем фрагов
local success, error = pcall(function()
FS:SetAsync(key, dust.Value)
end)

-- сохраняем расу
local success, error = pcall(function()
RS:SetAsync(key, race)
end)
end

players.PlayerAdded:connect(function(player)
player.CharacterAdded:Connect(function(character)
local key = player.userId
local folder = Instance.new("Folder", player)
folder.Name = "leaderstats"
local coin = Instance.new("IntValue", folder)
local dust = Instance.new("IntValue", folder)
coin.Name = "Coins"
dust.Name = "Stars"

-- считываем расу----
local success, raceName, keyInfo = pcall(function()
return RS:GetAsync(key)
end)

if success then player.Team = teams:FindFirstChild(raceName) or teams.Human -- выводим в лидерстат
end

-- считываем кол-во монет ----
local success, coinVal, keyInfo = pcall(function()
return CS:GetAsync(key)
end)

if success then coin.Value = coinVal or 100 -- выводим в лидерстат
end

-- считываем кол-во фрагов ----
local success, fragVal, keyInfo = pcall(function()
return FS:GetAsync(key)
end)

if success then dust.Value = fragVal or 0 -- выводим в лидерстат
end

character:WaitForChild("Humanoid").Died:Connect(function()
SaveStat(players:GetPlayerFromCharacter(character))
end)
end)
end)

players.PlayerRemoving:Connect(SaveStat)


- PlayerStartScript --
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local event2 = ReplicatedStorage.Events:WaitForChild("SetRaceEvent")

event2:FireServer()


-- SaveButtonScript -------
local players = game:GetService("Players")
local player = game.Players.LocalPlayer

players.CharacterAutoLoads = true

script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Parent.Frame.Visible = false

workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
end)