sm64-roblox-liberty-prime/server/StarterCharacter/Appearance/init.server.lua

179 lines
3.9 KiB
Lua
Raw Permalink Normal View History

2022-10-13 08:53:17 +00:00
--!strict
local Players = game:GetService("Players")
2023-07-08 23:42:28 +00:00
local character: Instance = assert(script.Parent)
assert(character:IsA("Model"), "Not a character")
2022-10-13 08:53:17 +00:00
2023-07-08 23:42:28 +00:00
local player = Players:GetPlayerFromCharacter(character)
assert(player, "No player!")
2022-10-13 08:53:17 +00:00
local userId = player.UserId
local hDesc: HumanoidDescription?
2023-07-08 23:42:28 +00:00
local metalPointers = {} :: {
[MeshPart]: {
Metal: SurfaceAppearance?,
},
}
local function updateMetal(part: MeshPart)
local isMetal = character:GetAttribute("Metal")
local ptr = metalPointers[part]
if ptr == nil then
ptr = {}
metalPointers[part] = ptr
end
if isMetal and not ptr.Metal then
local surface = script.METAL_MARIO:Clone()
surface.Parent = part
ptr.Metal = surface
elseif ptr.Metal and not isMetal then
ptr.Metal:Destroy()
ptr.Metal = nil
end
end
local function onMetalChanged()
for meshPart in metalPointers do
updateMetal(meshPart)
end
end
local function onDescendantAdded(desc: Instance)
if desc:IsA("BasePart") then
if desc.CollisionGroup ~= "Player" then
local canCollide = desc:GetPropertyChangedSignal("CanCollide")
desc.CollisionGroup = "Player"
2024-04-19 21:13:52 +00:00
desc.CanQuery = true
desc.CanTouch = true
2023-07-08 23:42:28 +00:00
desc.Massless = true
canCollide:Connect(function()
2024-04-19 21:13:52 +00:00
desc.CanCollide = true
2023-07-08 23:42:28 +00:00
end)
2022-10-13 08:53:17 +00:00
2024-04-19 21:13:52 +00:00
desc.CanCollide = true
2023-07-08 23:42:28 +00:00
end
2022-10-13 08:53:17 +00:00
2023-07-08 23:42:28 +00:00
if desc:IsA("MeshPart") then
updateMetal(desc)
end
2022-10-13 08:53:17 +00:00
end
end
2023-07-08 23:42:28 +00:00
local function onDescendantRemoving(desc: Instance)
if desc:IsA("MeshPart") then
metalPointers[desc] = nil
2022-10-13 08:53:17 +00:00
end
end
2023-07-08 23:42:28 +00:00
local metalListener = character:GetAttributeChangedSignal("Metal")
metalListener:Connect(onMetalChanged)
for i, desc in character:GetDescendants() do
task.spawn(onDescendantAdded, desc)
end
character:SetAttribute("TimeScale", 1)
2023-07-08 23:42:28 +00:00
character.DescendantAdded:Connect(onDescendantAdded)
character.DescendantRemoving:Connect(onDescendantRemoving)
2022-10-13 08:53:17 +00:00
2024-04-19 22:24:14 +00:00
--THIS IS WHERE THE SPAWNLOCATION IMPLEMENTATION IS
local function getTeamSpawnPosition(player)
local teamColor = player.TeamColor
local spawnLocations = game.Workspace:GetDescendants()
local teamSpawn = nil
-- Find a spawn location with the same TeamColor as the player's team
for _, spawn in pairs(spawnLocations) do
if spawn.ClassName == "SpawnLocation" then
if spawn.TeamColor == teamColor then
teamSpawn = spawn
break
end
end
end
if teamSpawn then
return teamSpawn.Position
else
warn("No spawn location found for team color: " .. tostring(teamColor))
return game.workspace:FindFirstChild("SpawnLocation") --default
end
end
2022-10-13 08:53:17 +00:00
local function reload()
character:ScaleTo(1)
2022-10-13 08:53:17 +00:00
for retry = 1, 10 do
local success, result = pcall(function()
return Players:GetHumanoidDescriptionFromUserId(userId)
end)
if success then
hDesc = result
break
else
task.wait(retry / 2)
end
end
if hDesc then
hDesc.HeadScale = 1.8
hDesc.WidthScale = 1.3
hDesc.DepthScale = 1.4
hDesc.HeightScale = 1.2
hDesc.BodyTypeScale = 0
hDesc.ProportionScale = 0
else
return
end
local humanoid = character:WaitForChild("Humanoid")
assert(hDesc)
if humanoid:IsA("Humanoid") then
while not humanoid.RootPart do
humanoid.Changed:Wait()
end
local rootPart = humanoid.RootPart
assert(rootPart, "No HumanoidRootPart??")
local particles = rootPart:FindFirstChild("Particles")
humanoid:ApplyDescription(hDesc)
if particles and particles:IsA("Attachment") then
local floorDec = humanoid.HipHeight + (rootPart.Size.Y / 2)
local pos = Vector3.new(0, -floorDec, 0)
rootPart.PivotOffset = CFrame.new(pos)
particles.Position = pos
end
end
end
local reset = Instance.new("RemoteEvent")
reset.Parent = character
reset.Name = "Reset"
reset.OnServerEvent:Connect(function(player)
if player == Players:GetPlayerFromCharacter(character) then
reload()
end
end)
2024-04-19 22:24:14 +00:00
local RunService = game:GetService("RunService")
function resetter()
if character.Humanoid.Health < 1 then
reload()
wait()
player:LoadCharacter()
end
end
2022-10-13 08:53:17 +00:00
task.spawn(reload)