I got this local script from an old post. I need a fire trail ability for my game and now I have this local script, I just need a server script that will make it work.
I have no idea how to do this, because i’ve never made holdable keybinds or anything like that. Thank you for any help. Here’s the local script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local fire = replicatedStorage.FireTrailSpell
local connection
local camera = workspace.CurrentCamera
local range = 30
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Whitelist
RayParams.FilterDescendantsInstances = {workspace.Baseplate,workspace.Ground} --insert the parts that you want the fire to appear on in here (these are just examples)
-- if player:GetRankInGroup(11133567) == 255 or player:GetRankInGroup(11133567) == 205 then
local function getWorldMousePos()
local mousePos = userInputService:GetMouseLocation()
local ray = camera:ViewportPointToRay(mousePos.X,mousePos.Y)
local direction = ray.Direction * range
local result = workspace:Raycast(ray.Origin, direction, RayParams)
if result then
return result.Position
else
return nil --return nothing because it isn't touching ground
end
end
userInputService.InputBegan:Connect(function(input, processed)
if processed then
return
end
if input.KeyCode == Enum.KeyCode.X then
if player:GetRankInGroup(11133567) == 205 or player:GetRankInGroup(11133567) == 255 then
fire:FireServer("On")
local BodyGyro
fire.OnClientEvent:Connect(function()
BodyGyro = Instance.new("BodyGyro")
BodyGyro.MaxTorque = Vector3.new(300, 300, 300)
BodyGyro.P = 10^7
BodyGyro.D = 100
BodyGyro.Parent = character:FindFirstChild("HumanoidRootPart")
connection = runService.RenderStepped:Connect(function()
runService.RenderStepped:Wait()
local WrldMousePos = getWorldMousePos()
if WrldMousePos then
local Direction = Vector3.new(WrldMousePos.X - character.HumanoidRootPart.Position.X, WrldMousePos.Y, WrldMousePos.Z - character.HumanoidRootPart.Position.Z)
BodyGyro.CFrame = CFrame.new(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position + Direction)
local Trail = workspace:FindFirstChild(player.Name.."'s Trail")
table.insert(RayParams.FilterDescendantsInstances,Trail)
if Trail then
local range = math.min(30, (character.HumanoidRootPart.Position - WrldMousePos).Magnitude)
local direction = (WrldMousePos - character.HumanoidRootPart.Position).Unit
Trail.CFrame = CFrame.new(character.HumanoidRootPart.Position + direction * range)
end
end
end)
end)
wait(20)
BodyGyro:Destroy()
connection:Disconnect()
fire:FireServer("Off")
end
end
end)