Why does my part freeze when I clone it and send it to workspace?

Hello, i have a minor problem, i do not know why when i clone the part and parent it to workspace and apply impuse, it doesnt apply instantly but it freezes for a bit in the air. I want to remove it.

Any help is appreciated!

the script:

local tool = script.Parent
local handle = tool:WaitForChild("Handle")

local RS = game:GetService("ReplicatedStorage")
local throwRemote = RS.Remotes.Throw
local killRemote = RS.Remotes.Kill
local killedRemote = RS.Remotes.Killed
local xpRemote = RS.Remotes.XP

local cooldown = .5
local isCooldown = false
local direction
local rayOrigin

local LevelModule = require(game:GetService("ServerScriptService").LevelModule)
local DataStore2 = require(game:GetService("ServerScriptService").DataStore2)

DataStore2.Combine("DATA", "XP")


throwRemote.OnServerEvent:Connect(function(plr, mouse, mouseray)
	rayOrigin = mouseray.Origin
	direction = ((mouse - rayOrigin).Unit) * 2
end)

tool.Activated:Connect(function()
	local plr = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
	if plr.Character:WaitForChild("Humanoid").Health <= 0 then return end

	local expStore = DataStore2("XP", plr) 
	local levelStore = DataStore2("Level", plr)
	
	local startPos = (plr.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -1)).Position -- put the starting position a bit in front of the character

	local toolclone = handle:Clone()
	toolclone.Parent = workspace
	toolclone:SetNetworkOwner(nil)
	toolclone.Killer.Value = plr
	--print(toolclone.Killer.Value)
	toolclone.Position = startPos
	toolclone.CanCollide = false
	toolclone.Anchored = false

	local forceMultipliter = 100 * toolclone:GetMass() -- we get the parts mass to make sure that if the part is bigger or smaller it will still go about the same distance
	toolclone:ApplyImpulse(direction * forceMultipliter)
	local randomangle = Vector3.new(math.random(-200,200), math.random(-200,200), math.random(-200,200))
	toolclone:ApplyAngularImpulse(toolclone.CFrame:VectorToWorldSpace(randomangle))
	
	
	local cooldownTable = {}
	toolclone.Touched:Connect(function(touched)
		--print(touched)
		if touched:IsDescendantOf(plr.Character) then wait(5) toolclone:Destroy() return end
		toolclone.CanCollide = true
		if not tool.Parent:IsAncestorOf(touched) or not tool.Parent.Parent:IsAncestorOf(touched) then
			if touched:IsDescendantOf(plr.Character) then wait(5) toolclone:Destroy() return end
			
			local humanoid = touched.Parent:FindFirstChild("Humanoid") or touched.Parent.Parent:FindFirstChild("Humanoid")

			if humanoid then
				if humanoid.Health > 0 then -- if player still alive 
					humanoid.Health = 0 --kill the player
					local plrKilled = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
					if not table.find(cooldownTable, humanoid.Parent.Name) then --for to stop spamming remote fires to clietn killfeed (dont remove this)
						table.insert(cooldownTable, humanoid.Parent.Name)
						if humanoid.Health <= 0 then
							killedRemote:FireClient(plrKilled, toolclone.Killer)
							killRemote:FireClient(plr, plrKilled)
							LevelModule.GiveXP(plr, LevelModule.playerKilled)
						end
						local a = table.find(cooldownTable, humanoid.Parent.Name)
						wait(1.5)
						table.remove(cooldownTable, a)
					end
				end
			end


			wait(5)
			toolclone:Destroy()
		end
	end)
end)

the localscript:

local tool = script.Parent

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local userInput = game:GetService("UserInputService")
local cam = workspace.CurrentCamera
local throwRemote = game:GetService("ReplicatedStorage").Remotes.Throw

tool.Activated:Connect(function()
	tool.Handle.Killer.Value = player
	-- Get mouse position:
	local mousePos = userInput:GetMouseLocation()
	
	-- Get the ray from the mouse and project it 1000 studs forward:
	local mouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y, 0)
	local mouseRay = mouse.UnitRay
	mouseRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 100)


	-- Cast the ray:
	local target, hit = workspace:FindPartOnRay(mouseRay)
	--print(target)
	throwRemote:FireServer(mouse.Hit.Position, mouseRay)
	--use p for position but remember to remove "lookVector in script"
end)

I believe that’s because of the Server, You cant remove it.

The only thing you could do do is:

  • Apply NetworkOwnership

  • Fire to All Clients that Effect

Well in that case, I’ll just apply an animation to make it look cool haha. Thanks for the help. I’ve already had that code, I just wasnt sure if it did anything.

Have a good day :slight_smile:

Here is something that may help:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.