I made a code for my key to drop when a character dies, it is working fine but the problem is if the character were in closed space the key would get stuck in the wall, anyone knows a way around this?
Like maybe make it force spawn in open space when a character dies.
My code to preserve the key when someone dies:
character.Humanoid.Died:connect(function()
if character:FindFirstChild("key") then
character.key.CanCollide = true
if character.key:FindFirstChild("WeldConstraint") then
character.key.WeldConstraint:Destroy()
end
character.key.ProximityPrompt.Enabled = true
character.key.Parent = workspace
end
end)
You could use GetPartBoundsInBox (WorldRoot | Roblox Creator Documentation) to see if the key is intersecting with anything. If it is you could raycast at it from 100 studs up to see where the ground is. You could then move the key to that position + half of the parts y size. If you need any help with coding this please ask.
CanQuery is a property for base parts that allows you to decide if a part is detected in spatial queries(things like raycasts and getting the parts in a specific area). I think you would be OK without using GetPartBoundsInBox.
local result = workspace:RayCast(character.key.Position+Vector3.new(0,100,0), character.key.Position - Vector3.new(0,100,0)
character.key.Position = result.Position
I’m sorry guys I think I didn’t explain it well.
What I meant is when the character is holding an item and it died it will drop the item on the same position so if the hand is clipping through a wall it will get stuck there, that is what I wanna fix not when it drops to the ground, but I think @RoloTheDevBunny idea is the solution of GetPartBoundsInBox but I don’t know how to apply it.
here is a reference picture (it is a small cabinet):