Part Delay (Wand System)

Heya everyone. Well, this is my first post here on the forum so I’m sorry if something goes wrong haha! So, I’ve been working on a small project for myself where I like to make some adjustments from time to time. However, for some days now, I have been facing a problem where I tried several to make it work, but I still have certain problems. Let me quickly explain:

It is a wand system, where the player has some spells and they can type the name of the spell in the chat that an event will be triggered and that will make a small check on the server to check if the player has that spell, if yes, the spell name will return to the client and the moment they click anywhere the spell is released with certain effects. It is a revamp, where I rewrote an entire and dedicated module for that system. There are four modules dedicated to the system, they are:

  • SpellsEvent → The module where all the necessary events and functions are stored.
  • SpellsHandler → The place where the list of spells and other less important functions are stored.
  • SpellsChatted → It contains a function that identifies when the spell is said in the chat and makes adjustments to some values.
  • Spells → A long module where all spell functions are stored.

So my problem is a little strange, even though I have seen similar cases here in the forum about it, I still can’t solve it or find an obvious solution.

Every time I press to release a spell, there is always a delay and only after the spell is released, even using SetNetworkOwner does not seem to help me, since I use BodyVelocity and so on. I will put a part of what I am using here, along with an example of a normal spell.

Spell base:

function Events.SpellBase(MousePos, Tool, Sound2, F, Name, Self, IsSpellbolt)
	
	local Character = Tool.Parent
	local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
	
	local Part = Instance.new("Part")
	Part.Parent = Workspace
	Part:SetNetworkOwner(nil)
	
	if Self == true then
		Part.CFrame = Tool:WaitForChild("WandTip").CFrame:ToWorldSpace(CFrame.new(-1.5, 0, 0))
	elseif Self == false or not Self then
		Part.CFrame = Tool:WaitForChild("WandTip").CFrame
	end
	
	Part.CFrame = Tool:WaitForChild("WandTip").CFrame:ToWorldSpace(CFrame.new(-1.5, 0, 0))
	Part.CFrame = CFrame.new(Part.CFrame.p, MousePos)	
	Part.Name = "Spell"
	
	local Angle = (MousePos - Part.CFrame.p).unit

	Part.Size = Vector3.new(0.5, 0.5, 0.5)
	Part.Material = "Neon"
	Part.Transparency = 1
	Part.CanCollide = false
	Part.Anchored = false
	
	local BodyVelocity = Instance.new("BodyVelocity", Part)
	BodyVelocity.Velocity = CFrame.new(Part.Position, MousePos).LookVector * 150
	BodyVelocity.MaxForce = Vector3.new(100000, 1000000, 1000000)
	BodyVelocity.P = 100000
	
	local Creator = Instance.new("ObjectValue")
	Creator.Value = game.Players:GetPlayerFromCharacter(Tool.Parent)
	Creator.Name = "Creator"
	Creator.Parent = Part
	
	local Collided = Instance.new("BoolValue")
	Collided.Value = false
	Collided.Name = "Collided"
	Collided.Parent = Part
	
	local SpellName = Instance.new("StringValue")
	SpellName.Value = Name
	SpellName.Name = "SpellName"
	SpellName.Parent = Part

	if Self == false or not Self then
		Events.CollisionDetection(Part, Tool, F, Sound2, false)
	elseif Self == true then
		Events.CollisionDetection(Part, Tool, F, Sound2, true)
	end
	
	SpellEffect:FireAllClients(Part, Tool)

	Events.AddToDebrisService(Part, 3)

	return Part
end

Spell example:

function Spells.EverteStatum(MousePos, Tool)
	
	Events.AddSound("http://www.roblox.com/asset/?id=211364696", Tool.Parent:FindFirstChild("HumanoidRootPart"))
	
	local Aim
	
	local function Push(Part)
		
		if Events.FindHumanoid(Part) then
			Events.FindHumanoid(Part):TakeDamage(25)
			
			local Model = Events.FindHumanoid(Part).Parent
			Model.Humanoid.Jump = true
			Model.Humanoid.Sit = true
			
			local BodyForce = Instance.new("BodyForce")
			BodyForce.Force = Vector3.new(1, 1, 1) * Aim * Events.GetHumanoidModelMass(Model) * 200
			BodyForce.Parent = Model:FindFirstChild("HumanoidRootPart")
			
			Events.AddToDebrisService(BodyForce, 0.5)
			
			Model:FindFirstChild("HumanoidRootPart").RotVelocity = 2.5 * Vector3.new(math.random() * 10, math.random() * 10, math.random() * 10)
		else
			if not Part.Anchored then
				Part.Velocity = Part:GetMass() / 8 * Aim
			end
		end
	end
	
	local Spell = Events.SpellBase(MousePos, Tool, "rbxassetid://255679373", Push, "Everte Statum")
	Spell.Color = Color3.fromRGB(39, 20, 186)
	Aim = Spell.CFrame.LookVector
end

If possible, I would like to have feedback on what I could do to remove this delay and make everything go normal, as this lag doesn’t seem right. See an example of what happens below:

3 Likes

The issue is the part where you check the server to make sure that they have the spell. Instead of doing that when they use the spell. You should do a client check to see if they have the spell. If they do, make the spell effects on the client then fire the server. The server checks to see if they have the spell. if they do, it should tell other clients to make the effects on their side.

this will make the server have less of a load and will make good us of the processing power that players have. It will make the client have less input lag and make moves look smoother.

so
Player who uses magic Client:

tool.Activated:Connect(function()
--Check if they have the magic
--if they do make the effect desired
--Fire Server with needed information
end)

server:

Event.OnServerEvent:Connect(function(Player, ...)
--Make sure player has magic 
--if they do fire all the other clients with the information needed to make effects
end)

Client script for all other players:

Event.OnClientEvent:Connect(function(...)
--make effects for this client to see
end)
2 Likes

Thank you, I didn’t really use all of your method but I made another one which uses FireAllClients to apply the spell effects, it works now. Thank you! :purple_heart:

1 Like