local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = game.Workspace.CurrentCamera
local tool = script.Parent -- Assuming the tool is under the script
-- Variable to track the transformed part
local transformedPart = nil
local toolEnabled = true -- Flag to enable/disable the tool
local lastTransformedTime = 0 -- Track the last time transformation occurred
local cooldownTime = 5 -- Cooldown time in seconds
local transformDuration = 5 -- Duration for the part to last in seconds
-- Function to restore the character's visibility and collision
local function restoreCharacterVisibility(character)
-- Make the entire character (including accessories) visible
for _, v in pairs(character:GetChildren()) do
if v:IsA("BasePart") or v:IsA("MeshPart") then
v.Transparency = 0
v.CanCollide = true -- Restore collision
elseif v:IsA("Accessory") then
-- Restore each part inside the accessory
for _, accessoryPart in pairs(v:GetChildren()) do
if accessoryPart:IsA("BasePart") or accessoryPart:IsA("MeshPart") then
accessoryPart.Transparency = 0
accessoryPart.CanCollide = true
end
end
end
end
end
-- Function to handle the player's death and remove the part
local function onPlayerDeath()
-- If the transformed part exists, remove it from the workspace
if transformedPart then
transformedPart:Destroy()
transformedPart = nil -- Clear the reference to the transformed part
end
-- Disable the tool functionality upon death
toolEnabled = false
-- Make the character visible and restore collision upon death
local character = player.Character
if character then
restoreCharacterVisibility(character)
end
end
-- Connect death event to handle the player's death
player.CharacterAdded:Connect(function(character)
-- When the character is added, listen for death
character:WaitForChild("Humanoid").Died:Connect(onPlayerDeath)
end)
-- Function to handle transformation into a part
local function transformIntoPart()
if not toolEnabled then
print("You cannot transform because you're dead or on cooldown.")
return
end
-- Check if cooldown period has passed
if tick() - lastTransformedTime < cooldownTime then
print("You need to wait before transforming again.")
return
end
-- Create a ray from the camera to where the mouse is pointing
local origin = camera.CFrame.Position
local direction = (mouse.Hit.Position - origin).unit * 16 -- Raycast for 16 studs
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character} -- Ignore player’s own character
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local rayResult = workspace:Raycast(origin, direction, raycastParams)
if rayResult then
local hitPart = rayResult.Instance
if hitPart and hitPart:IsA("BasePart") then
local size = hitPart.Size
-- Check if part size is smaller than 10 for all dimensions
if size.X < 10 and size.Y < 10 and size.Z < 10 then
print("You're looking at a valid part: " .. hitPart.Name)
-- Get player character
local character = player.Character
if not character then return end
-- Make the entire character (including accessories) invisible
for _, v in pairs(character:GetChildren()) do
if v:IsA("BasePart") or v:IsA("MeshPart") then
v.Transparency = 1
v.CanCollide = false -- Prevent collision
elseif v:IsA("Accessory") then
-- Make each part inside the accessory invisible
for _, accessoryPart in pairs(v:GetChildren()) do
if accessoryPart:IsA("BasePart") or accessoryPart:IsA("MeshPart") then
accessoryPart.Transparency = 1
accessoryPart.CanCollide = false
end
end
end
end
-- Clone the part and make it the player's new body
local newBody = hitPart:Clone()
newBody.Parent = workspace
newBody.Name = "TransformedPart" -- Give it a name to track it
-- Adjust the part's position so it touches the ground
local rayDown = workspace:Raycast(newBody.Position, Vector3.new(0, -50, 0)) -- Raycast downward
if rayDown then
newBody.Position = rayDown.Position + Vector3.new(0, newBody.Size.Y / 2, 0) -- Offset to sit on ground
else
-- If no ground is found, position at original position
newBody.Position = character.HumanoidRootPart.Position
end
newBody.Anchored = false -- So physics work
-- Weld the new part to the player
local weld = Instance.new("WeldConstraint")
weld.Part0 = newBody
weld.Part1 = character.HumanoidRootPart
weld.Parent = newBody
-- Store the reference to the transformed part
transformedPart = newBody
-- Set the last transformed time and start a timer to remove the part
lastTransformedTime = tick()
print("Transformed into:", hitPart.Name)
-- Set a timer to destroy the part after the duration (transformDuration seconds)
delay(transformDuration, function()
if transformedPart then
-- Ensure weld is removed before destroying the part
for _, weld in pairs(transformedPart:GetChildren()) do
if weld:IsA("WeldConstraint") then
weld:Destroy()
end
end
-- Make the transformed part transparent before destruction
transformedPart.Transparency = 1
transformedPart.CanCollide = false
-- Wait for a moment to ensure transparency change is visible
wait(0.5)
-- Now destroy the part
transformedPart:Destroy()
transformedPart = nil -- Clear reference
print("Your transformed part has disappeared.")
if player.Character then
restoreCharacterVisibility(player.Character)
end
end
end)
else
print("Part is too big.")
end
end
else
print("No part detected.")
end
end
mouse.Button1Down:Connect(transformIntoPart)
Ok so that would be the HumanoidRootPart, by default its transparency is 1, and I assume that somewhere you set all baseparts inside of your character to 0 (the transparency that is.).
In order to fix this, when you set the transparency to 0, just make sure that its name isnt “HumanoidRootPart”
:D
1 Like
thx It turned out to be so easy but I didn’t know
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.