How to fix major tool delay

It will be difficult to describe this in words so I will show a video example
robloxapp-20200413-1112176.wmv (2.6 MB) Tell me if there is a more preffesional way to upload videos
As you can see there is very annoying delay as I will click facing to the left for example, but the part will appear where I was facing a half a second before.

local Tool = script.Parent
local enabled = true
function Activated()
	if enabled then
		--enabled = false
		local part = game.Lighting.DamagePart:Clone()
		part.CFrame = script.Parent.Parent.Head.CFrame*CFrame.new(0,0,-2)
		part.Orientation = Vector3.new (script.Parent.Parent.Head.Orientation.X,script.Parent.Parent.Head.Orientation.Y,script.Parent.Parent.Head.Orientation.Z)
		part.Parent = game.Workspace
		--part.Launcher.Value = script.Parent.Parent.Name
		--wait(1)
		--enabled = true
	end
end
Tool.Activated:Connect(Activated)

I commented out things you don’t need to worry about (it does work with and without the comments)

1 Like

You’re only running if enabled as in. If this is enabled, turn enabled off. Which means it’s no longer enabled so there is no way to continue the script. I might be wrong though.

1 Like

the script can run as many times as it wants, the issue isn’t that the script is running only once. The issue is that there is a fairly large delay between clicking and and the object being cloned, and like I said, the script runs the same with and without the commented out things commented out

2 Likes

Tool activation is client-side input that’s replicated (AFAIK), so the server needs to receive that signal internally before it determines that it should be firing. If the part is appearing in the wrong place, that’s because the character’s position on the client and server are different. Clients will see a live position of their character while the server follows up in infrequent intervals.

Visualisations can just be handled by each client, the current client through the LocalScript and others after being told through a remote. If you need any server-side actions (damaging, replication of something), that can also be part of the action process after a remote is fired after telling other clients that they need to visualise something.

2 Likes

so what you’re telling me is that there is no way to fix this issue :sad:

1 Like

There technically is, which I mentioned in my post. Don’t do any visualising work on the server. All clients should be responsible for handling visualisations on their own characters as well as on others.

The client using the tool will visualise the part and fire a remote to the server. The server, if it needs to do any validation logic first so that a client isn’t taking advantage of the server to replicate actions where it shouldn’t be. If all checks pass, then the server will tell all other clients to visualise the part on the tool user’s character. Afterward, if the server needs to handle any critical actions, it will do so.

Other clients, through a LocalScript preferably in PlayerScripts (populated from StarterPlayerScripts) will connect to that RemoteEvent. When the server fires the remote on the client, it will essentially receive a message to start visualising the part on the tool user’s character.

1 Like

Well this is very annoying because I was planning on using that part for damage, and we all know that local scripts only work on client side. Is there ANY way to reduce this lag on a normal script?

1 Like

There isn’t. The client and server don’t see the same character positions immediately and there’s no way to force them to do so either without breaking something or making the delay on the client equally worse.

2 Likes