Как создать кнопку удаления персонажа из DataStory в Roblox Studio?
Meilleur 42
Ученик
(96),
на голосовании
2 недели назад
как создать кнопку которая будит удалять персонажа из памяти DataStory и заменять его на базового персонажа. Персонаж находится по этому пути .ReplicatedStorage.Characters.Common.Citizen. Пример такой кнопки есть в плейсе "World of Trolls".
local button = script.Parent local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Define the spawn location local spawnLocation = workspace:WaitForChild("SpawnLocation") -- Make sure you have a SpawnLocation part in your workspace
button.MouseButton1Click:Connect(function() local player = Players.LocalPlayer local character = player.Character
if character then character:Destroy() end
-- Clone the new character and set it up local newCharacter = ReplicatedStorage.Characters.Common.Citizen:Clone() newCharacter.Name = player.Name -- Ensure the character has the player's name newCharacter.Parent = workspace player.Character = newCharacter
-- Wait for the character to be set up before making adjustments newCharacter:WaitForChild("HumanoidRootPart") newCharacter:WaitForChild("Humanoid")
-- Move the new character to the spawn location newCharacter:SetPrimaryPartCFrame(spawnLocation.CFrame)
-- Set the camera to follow the new character workspace.CurrentCamera.CameraSubject = newCharacter:FindFirstChild("Humanoid") workspace.CurrentCamera.CameraType = Enum.CameraType.Custom end)
Дополнен 1 месяц назад
И еще GUI не должен пропадать при нажатии на кнопку удаления
local button = script.Parent
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Define the spawn location
local spawnLocation = workspace:WaitForChild("SpawnLocation") -- Make sure you have a SpawnLocation part in your workspace
button.MouseButton1Click:Connect(function()
local player = Players.LocalPlayer
local character = player.Character
if character then
character:Destroy()
end
-- Clone the new character and set it up
local newCharacter = ReplicatedStorage.Characters.Common.Citizen:Clone()
newCharacter.Name = player.Name -- Ensure the character has the player's name
newCharacter.Parent = workspace
player.Character = newCharacter
-- Wait for the character to be set up before making adjustments
newCharacter:WaitForChild("HumanoidRootPart")
newCharacter:WaitForChild("Humanoid")
-- Move the new character to the spawn location
newCharacter:SetPrimaryPartCFrame(spawnLocation.CFrame)
-- Set the camera to follow the new character
workspace.CurrentCamera.CameraSubject = newCharacter:FindFirstChild("Humanoid")
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)