i was wondering which code i should use and which one is more efficient. i would like some help with the most efficient one. Since they’re not the best and the second one doesn’t even work properly. Pretty much what these scripts are suppose to do is, as soon as a player activates a touch event it would turn each of their body parts into parts and slowly disappear (i already have scripted the part where the body parts gets replaced by parts and slowly disappear, this part is in a module script)
my issue here is sometimes when a player dies and spawns too fast or if a player leaves the game while the script is running it would error and break the whole script for the first one. and for the second script it would just spawn too much parts and not really replace all the body parts of a player, and it also errors because it keeps getting the humanoid which is not an actual part.
i’ve been looking on the GetChildren() page on the devfourm i understand it a bit(second script), and the first script i kind of figured out everything on my own but then i just get errors i don’t really know how to fix without breaking everything
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local mainPart = script.Parent
local modulescript = game.ServerScriptService.ModuleScript
local debounce = false
mainPart.Touched:Connect(function(touchedpart)
if touchedpart.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
for _, Player in ipairs(mainPart:GetTouchingParts()) do
touchedpart.Parent.Humanoid.WalkSpeed = 5
touchedpart.Parent.Humanoid.JumpPower = 1
if Player.Transparency == 0 then
if Player == ("HumanoidRootPart") then
else
local Carmodule = require(modulescript)
Carmodule.player(Player)
print(Player)
end
end
end
wait(0.5)
debounce = false
end
end
end)
--- this is the first script
local mainPart = script.Parent
local modulescript = game.ServerScriptService.ModuleScript
local debounce = false
mainPart.Touched:Connect(function(touchedpart)
if touchedpart.Parent:FindFirstChild("Humanoid") then
local Player = touchedpart
if debounce == false then
debounce = true
local children = touchedpart.Parent.Humanoid.Parent:GetChildren()
for i, child in ipairs(children) do
print(children)
if Player.Transparency == 0 then
if Player == ("HumanoidRootPart") then
else
local Carmodule = require(modulescript)
Carmodule.player(Player)
print(Player)
end
end
end
end
wait(0.5)
debounce = false
end
end)
--- this is the second script
I’m not really sure what you are trying to do. The character is already comprised of base parts.
You should probably use :GetDescendants() on the character and if it’s a basepart then tween it. :GetChildren() refers to the hierarchy of the parts, a child is an instance who is directly under a specific instance.
You also aren’t using if statements properly, an instance is never equal to a string. You have to check its name. You are missing ends and a lot of other things, I can’t really see the point of a lot of what you are doing.
Also, you are going through the hierarchy of the model so much that it’s a bit difficult to read, I’ll help you clean it up a bit.
local tweenService = game:GetService('TweenService')
local debounce = false
mainPart.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild('Humanoid')
if humanoid and (not debounce) then
debounce = true
for i,v in pairs(touchedPart.Parent:GetDescendants()) do
if v:IsA('BasePart') and v.Name ~= 'HumanoidRootPart' then
tweenService:Create(v, TweenInfo.new(0.5), {Transparency = 1}):Play()
end
end
end
end
what i was trying to say is , I’m trying to do something like the one, where i touched the blue box, this helps and i was trying to make it do it all at once like your script. and also this is the module script it’s very messy
function Carmodule.player(Player)
wait(0.1)
local colorKeypoints = {
-- API: ColorSequenceKeypoint.new(time, color)
ColorSequenceKeypoint.new( 0, Color3.new(0.666667, 0.666667, 0)), -- At t=0, green
ColorSequenceKeypoint.new( 1, Color3.new(0.333333, 0.666667, 0)) -- At t=0, Light green
}
local numberKeypoints2 = {
NumberSequenceKeypoint.new(0, 0); -- At t=0, size of 0
NumberSequenceKeypoint.new(1, 0.5); -- At t=1, size of 10
}
Player.Transparency = 0.99
local replace = Instance.new("Part")
replace.Position = Player.Position
replace.CFrame = Player.CFrame
replace.Parent = Player
replace.Size = Player.Size
replace.CanCollide = true
replace.Material = Enum.Material.Neon
replace.BrickColor = BrickColor.new("Artichoke")
local weld = Instance.new("WeldConstraint")
weld.Parent = Player
weld.Part0 = Player
weld.Part1 = replace
Player:BreakJoints()
local sound = Instance.new("Sound")
sound.Parent = replace
sound.SoundId = "rbxassetid://1355880382"
sound.Playing = true
sound.Volume = 0.2
local Particle = Instance.new("ParticleEmitter")
Particle.Parent = replace
Particle.Rate = 10
Particle.Lifetime = NumberRange.new(1,1)
Particle.Texture = "http://www.roblox.com/asset/?id=467188845"
Particle.Color = ColorSequence.new(colorKeypoints)
Particle.Size = NumberSequence.new(numberKeypoints2)
Particle.Acceleration = Vector3.new(0, 1, 0)
Particle.Drag = 5
Particle.LockedToPart = false
local modulescript = game.ServerScriptService.ModuleScript
local Carmodule = require(modulescript)
Carmodule.slowly(Player,replace)
end
function Carmodule.slowly(Player,replace)
local Tween = game:GetService("TweenService")
local info = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In,0,false,0)
local goals = {Transparency = 1;}
local movepart = Tween:Create(replace, info, goals)
movepart:Play()
end
return Carmodule