Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make the trail work in a live server?

Asked by 5 years ago

local lPlayer = game.Players.LocalPlayer
local char = lPlayer.Character
local debounce = false

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.F then
        if not debounce then
            debounce = true
            local clonetrail = script.Parent.trail:Clone()
            char.Humanoid.WalkSpeed = 64
            clonetrail.Parent = char
            wait(5)
            clonetrail:Destroy()
            char.Humanoid.WalkSpeed = 16
            wait(8)
            debounce = false
        end
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
0
Are you using a server-side script (Script) or a client-side script (LocalScript)? If the former, you'll want to make sure you're using a LocalScript. Also make sure the script is not in a public place like Workspace or ServerScriptService. ChemicalHex 979 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You need to use the Attachment0 and Attachment1 properties of the Trail object. Your script also errors on line 2, since the Character needs time to load.

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

function maketrail()
    if not char:FindFirstChildOfClass"Trail" then
        local trail = Instance.new"Trail"
        trail.Parent = char
        trail.Attachment0 = waitforchild(char.Head, "TrailAttachment0")
        trail.Attachment1 = waitforchild(char.HumanoidRootPart, "TrailAttachment1")
    end

    if not char:FindFirstChild('TrailAttachment0', true) then
        local attachment0 = Instance.new"Attachment"
        attachment0.Name = "TrailAttachment0"
        attachment0.Parent = char:WaitForChild"Head"
    end

    if not char:FindFirstChild('TrailAttachment1', true) then
        local attachment1 = Instance.new"Attachment"
        attachment1.Name = "TrailAttachment1"
        attachment1.Parent = char:WaitForChild"HumanoidRootPart"
    end
end

function waitforchild(parent, child)
    parent:WaitForChild(child)
end

game:GetService("ContextActionService"):BindAction(
    "MakeTrail",
    maketrail,
    false,
    Enum.KeyCode.F
)
Ad

Answer this question