How to make this local script server sided (dash ability)

I’m so confused

local MAX_JUMPS = 1;
local MAX_DIVES = 1;
local TIME_BETWEEN_JUMPS = 0.1;

local hrp = script.Parent:WaitForChild("HumanoidRootPart");
local head = script.Parent:WaitForChild("Head");
local humanoid = script.Parent:WaitForChild("Humanoid");
local particle = script:WaitForChild("Particle");
particle.Parent = nil;

local anim;
if (humanoid.RigType == Enum.HumanoidRigType.R15) then
	anim = humanoid:LoadAnimation(script:WaitForChild("Roll_R15"));
else
	anim = humanoid:LoadAnimation(script:WaitForChild("Roll_R6"));
end

local canJump = true;
local jumpCount = 0;

local canDive = true;
local diveCount = 0;
local totalDives = 0;

local function createParticle(cf, t)
	game.Workspace.Effects.Attack:Play()
	local part = Instance.new("Part");
	part.Size = Vector3.new(4, 4, 4)
	part.Anchored = true;
	part.CanCollide = false;
	part.Transparency = 1;
	part.CFrame = cf;
	part.Parent = game.Workspace;
	
	local clone = particle:Clone();
	clone.Enabled = true;
	clone.Parent = part;
	
	local life = clone.Lifetime;
	for i = 0, 1.1, 0.1 do
		clone.Lifetime = NumberRange.new((1-i)*life.Min, (1-i)*life.Max + 0.1);
		wait(t*0.1);
	end

	game:GetService("Debris"):AddItem(part, t);
end

local function onStateChange(old, new)
	if (new == Enum.HumanoidStateType.Landed or new == Enum.HumanoidStateType.Swimming or new == Enum.HumanoidStateType.Running or new == Enum.HumanoidStateType.RunningNoPhysics) then	
		canDive = true;
		canJump = true;
		jumpCount = 0;
		diveCount = 0;
		anim:Stop();
	elseif (new == Enum.HumanoidStateType.Freefall or new == Enum.HumanoidStateType.Flying) then
		wait(TIME_BETWEEN_JUMPS)
		canJump = true;
		canDive = true;
	end
end

local function onJumpRequest()
	if (not humanoid or humanoid:GetState() == Enum.HumanoidStateType.Dead) then
		return;
	end
	
	if (canJump and jumpCount < MAX_JUMPS) then
		canJump = false;
		jumpCount = jumpCount + 1;
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping);
		
		if (jumpCount > 1) then
			if (jumpCount % 2 == 0 or humanoid:GetState() == Enum.HumanoidStateType.Flying) then
				anim:Play(nil, nil, 2.5);
			end
			local z = hrp.CFrame:vectorToObjectSpace(hrp.Velocity).z;
			createParticle(hrp.CFrame * CFrame.new(0, -1, 0), .3);
		end
	end
end

local function onInput(input, process)
	if (process or not humanoid or humanoid:GetState() == Enum.HumanoidStateType.Dead) then
		return;
	end	
	
	if (input.KeyCode == Enum.KeyCode.Space and humanoid:GetState() == Enum.HumanoidStateType.Freefall and canDive and diveCount < MAX_DIVES) then
		canDive = false;
		diveCount = diveCount + 1;
		totalDives = totalDives + 1;
		
		anim:Stop();
		humanoid:ChangeState(Enum.HumanoidStateType.Flying);
		hrp.Velocity = hrp.CFrame:vectorToWorldSpace(Vector3.new(0, humanoid.JumpPower, -humanoid.WalkSpeed*3));
		hrp.RotVelocity = hrp.CFrame:vectorToWorldSpace(Vector3.new(-math.rad(135), 0, 0));
		createParticle(hrp.CFrame * CFrame.new(0, -1, -3), .3);
		

		local currentDive = totalDives;
		wait(0.5);
		if (currentDive == totalDives) then
			hrp.RotVelocity = hrp.CFrame:vectorToWorldSpace(Vector3.new(0, 0, 0));
		end
	end
end

local function onTouched(touchingPart, humanoidPart)
	if (humanoid:GetState() == Enum.HumanoidStateType.Flying and touchingPart.CanCollide) then
		local ray = Ray.new(humanoidPart.Position, -humanoidPart.Velocity * 10);
		local hit, pos, normal, material = game.Workspace:FindPartOnRayWithWhitelist(ray, {touchingPart});
	
		if (material ~= Enum.Material.Water and material ~= Enum.Material.Air and normal:Dot(Vector3.new(0, 1, 0)) <= 0.5) then
			hrp.Velocity = (normal + Vector3.new(0, 1, 0)) * 30;
			anim:Play(nil, nil, 2.5);
		end
		
		humanoid:ChangeState(Enum.HumanoidStateType.Freefall);
	end
end

if (MAX_DIVES > 0) then
	humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false);
	humanoid.Touched:Connect(onTouched);
	game:GetService("UserInputService").InputBegan:Connect(onInput);
end

humanoid.StateChanged:Connect(onStateChange);
game:GetService("UserInputService").JumpRequest:Connect(onJumpRequest);

Why do you want it server side?, making it server side will make it sluggish for the players losing its smoothness.

oh because it creates a part to workspace for particles

what you can do is use Fireclient atleast the exploiters wont be able to spam it by adding a cooldown on the server script that fires client, but that could also cause delays depending on the player’s ping.

so it makes more sense to leave it local

Either way the effects wont be seen by other players cause its local only so even if the exploiters spam the effect they’ll be the only one dealing with aftermath

1 Like