I am creating a fairly basic system by which the player leaves a clone of themselves after dying from a spike, but I am experiencing an issue regarding the placement of the clone itself.
Here are a couple of videos to illustrate my problem:
Here is my script for reference:
local Debris = game:GetService("Debris")
local Player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:FindFirstChild("Humanoid")
local CharacterBodyDuration = 1000000
Humanoid.Died:Connect(function()
if Player ~= nil and Humanoid ~= nil then
Character.Archivable = true
script.Parent = game:GetService("ServerScriptService")
local ClonedCharacter = Character:Clone()
ClonedCharacter.Name = Player.Name.."'s body"
wait(0.1)
ClonedCharacter.Parent = game.Workspace.Remains
local Centre = ClonedCharacter.HumanoidRootPart or ClonedCharacter.Torso
local ClonedHumanoid = ClonedCharacter:FindFirstChildOfClass("Humanoid")
ClonedCharacter:MoveTo(Centre.Position)
ClonedHumanoid.PlatformStand = true
ClonedHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
ClonedHumanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
for i, v in pairs (ClonedCharacter:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
v.CanCollide = true
end
if v:IsA("Script") or v:IsA("LocalScript") then
v:Destroy()
end
end
if ClonedCharacter:FindFirstChild("ForceField") then
ClonedCharacter:FindFirstChild("ForceField"):Destroy()
end
Character.Parent = game:GetService("ServerStorage")
Debris:AddItem(ClonedCharacter, CharacterBodyDuration)
Debris:AddItem(script, CharacterBodyDuration)
wait(1)
end
end)
I have a feeling that my proposed system might require the .Touched event and CollectiveService (as there are multiple spikes!), but I have no idea how I would frame that.
I think the best thing would be using raycast. Because you can position the Head when somethings touched the part and it’ll position where it touched.
Since this is a very new area of learning for me, I am experiencing some trouble regarding the format of the raycast system, and how I would relate that to the player death script and its code to position the player’s dead body. Please note that the death script is local, and the spike script is a regular script. I would assume that I would need a remote event to link the two.
This is what I have so far in my script (not local):
local CollectionService = game:GetService("CollectionService")
local TaggedParts = CollectionService:GetTagged("Spike")
for i, TaggedPart in pairs (TaggedParts) do
TaggedPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent.Humanoid:TakeDamage(100)
end
while wait() do
local RaycastOrigin = Vector3.new(0, 0, 0)
local RayCastEnd = game.Workspace:WaitForChild("Technop_th")
local RaycastResult = game.Workspace.Spikes:GetChildren():Raycast(RaycastOrigin, RayCastEnd) -- attempt to call missing method 'Raycast' of table
print("Instance:", RaycastResult.Instance)
print("Position:", RaycastResult.Position)
print("Distance:", RaycastResult.Distance)
print("Material:", RaycastResult.Material)
print("Normal:", RaycastResult.Normal)
end
end)
end
Couldn’t you just set the CFrame with corpse:PivotTo(cf) if it’s a model you’re working with? My first thought as to why this was happening was that it might be because you’re using Vector3 (the position) which tends to not be as accurate as it will take into consideration parts that are in the way, unless they changed it’s behavior
Yeah I think this is it, it looks like the corpse spawns right on top of the actual character
local Centre = ClonedCharacter.HumanoidRootPart or ClonedCharacter.Torso
local ClonedHumanoid = ClonedCharacter:FindFirstChildOfClass("Humanoid")
ClonedCharacter:PivotTo(Centre.CFrame)