This must seem like a weird question, but here it goes.
So in my game, my guns are created by CFraming the head of the player to the players mouse. I then CFrame the gun and arms to the head of the player. What im trying to do is delay the CFrame so i wont get the current Frame's CFrame it will be like the last frames CFrame. I dont want to loose the 60 frame speed i currently have with this weapon either. ( just so i dont have a stuttery weapon)
function load() Tool = script.Parent Player = game.Players.LocalPlayer Camera = game.Workspace.CurrentCamera Mouse = Player:GetMouse() local weld1 = Instance.new("Weld") weld1.Parent = Game.JointsService weld1.C1 = Player.Character.Head.CFrame:toObjectSpace(Player.Character.Torso.CFrame) weld1.Part0 = Player.Character.Torso weld1.Part1 = Player.Character.Head game:GetService("RunService").RenderStepped:connect(function() --What makes the head aim to the mouse weld1.C1 = CFrame.new(Player.Character.Head.CFrame.p, Mouse.Hit.p):toObjectSpace(Player.Character.Torso.CFrame) end) end wait(2) load()
This is the script i use that makes the players head look torward their mouse.
Im looking to not run the current CFrame but make it delayed.
This is a simple variable manipulation problem!
The idea is to calculate the CFrame for the current frame and store that in a variable. Then, in the next frame you would set the weld's offset to the variable and repeat. This makes sure that you keep your code running alongside the user's framerate.
Your RenderStepped should be fixed to something like this...
local lastCalculation = weld.C1 -- for the first time RenderStepped runs game:GetService("RunService").RenderStepped:connect(function() local currentCalculation = CFrame.new() -- do your calculation here weld.C1 = lastCalculation -- set your weld to the last calculation lastCalculation = currentCalculation -- save the calculation for the next frame end)
There is a way it's called the Delay
function, Here is an Example layout(if you don't Understand the Wiki's layout).
function printer()--my Function print("Boom") end delay(5,printer)--this is where the delay gets used.
Now lets add it to your script:
function load() Tool = script.Parent Player = game.Players.LocalPlayer Camera = game.Workspace.CurrentCamera Mouse = Player:GetMouse() local weld1 = Instance.new("Weld") weld1.Parent = Game.JointsService weld1.C1 = Player.Character.Head.CFrame:toObjectSpace(Player.Character.Torso.CFrame) weld1.Part0 = Player.Character.Torso weld1.Part1 = Player.Character.Head game:GetService("RunService").RenderStepped:connect(function() --What makes the head aim to the mouse weld1.C1 = CFrame.new(Player.Character.Head.CFrame.p, Mouse.Hit.p):toObjectSpace(Player.Character.Torso.CFrame) end) end delay(2,load)
HOPE THIS HELPED!
Locked by woodengop and YellowoTide
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?