Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Part Keeps on being Transparent When Cloned?

So i was just messing around with Tweening and such, When i click R it launches a shockwave, But when i click again it will be still Invisible, What do i do here ( the shockwave is not invisible in default), You will understand what i mean when you read the scripts

Local Script

--------------Variables----------------
local rp = game:GetService("ReplicatedStorage")
local PunchEvent = rp:WaitForChild("Punch")
local UIS = game:GetService("UserInputService")
--------------------------------------------


-------------------EventCall----------------
UIS.InputBegan:Connect(function(Input,IsTyping)
	if IsTyping then
		return
		elseif Input.KeyCode == Enum.KeyCode.R then
			PunchEvent:FireServer()
			print("e")
		end
		
	end)



Server Script:

-------variables-----------
local rp = game:GetService("ReplicatedStorage")
local PunchEvent = rp:WaitForChild("Punch")
local punch = game.Workspace.Punch:Clone()
local Tween = game:GetService("TweenService")

-----------------EventCall----------
PunchEvent.OnServerEvent:Connect(function(Player)
	local character = Player.Character
	local HumRP = character:WaitForChild("HumanoidRootPart")
	punch.Name = Player.Name.."'s Punch"
	punch.Parent = character
	punch.CFrame = HumRP.CFrame * CFrame.new(0,0,-3)
	print("f")
	local reach = {}
	reach.Size = punch.Size + Vector3.new(3,3,3)
	local info = TweenInfo.new(.72)
	local tweens = Tween:Create(punch,info,reach)
	tweens:Play()
	
	local reach2 = {}
	reach2.CFrame = punch.CFrame * CFrame.new(0,0,-77)
	reach2.Transparency = punch.Transparency + (1 - punch.Transparency)
	local info = TweenInfo.new(1.2,Enum.EasingStyle.Linear)
	local tweenss = Tween:Create(punch,info,reach2)
	tweenss:Play()
	
	
end)

What do i do here?, i've tried Destroy() with a wait(), But that reaches to a Nil Value ( i want the shockwave to be visible once the tween is over) Sorry if you did not understand, I am bad at explaining :P

1 answer

✓ Accepted answer

The clone function returns a single object: the clone that was created. The 'punch' variable is not calling the clone function each time you index it, so you really only have one single punch object that you are reusing. Since it's always using the same object that was cloned at the start of the script, all of the changes made by the server script after the first call of the event will affect future uses of said event. I suggest cloning the object as soon as the event is called and destroying the object once you are done with it to prevent reusing an 'old' object.

1 comment

0

Thank you for the help!

This discussion is preserved as it was. New answers, comments, and votes are closed.