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)
01 | function load () |
02 |
03 | Tool = script.Parent |
04 | Player = game.Players.LocalPlayer |
05 | Camera = game.Workspace.CurrentCamera |
06 | Mouse = Player:GetMouse() |
07 |
08 | local weld 1 = Instance.new( "Weld" ) |
09 | weld 1. Parent = Game.JointsService |
10 | weld 1. C 1 = Player.Character.Head.CFrame:toObjectSpace(Player.Character.Torso.CFrame) |
11 | weld 1. Part 0 = Player.Character.Torso |
12 | weld 1. Part 1 = Player.Character.Head |
13 |
14 | game:GetService( "RunService" ).RenderStepped:connect( function () --What makes the head aim to the mouse |
15 | weld 1. C 1 = CFrame.new(Player.Character.Head.CFrame.p, Mouse.Hit.p):toObjectSpace(Player.Character.Torso.CFrame) |
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 question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?
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...
1 | local lastCalculation = weld.C 1 -- for the first time RenderStepped runs |
2 | game:GetService( "RunService" ).RenderStepped:connect( function () |
3 | local currentCalculation = CFrame.new() -- do your calculation here |
4 | weld.C 1 = lastCalculation -- set your weld to the last calculation |
5 | lastCalculation = currentCalculation -- save the calculation for the next frame |
6 | 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).
1 | function printer() --my Function |
2 | print ( "Boom" ) |
3 | end |
4 |
5 | delay( 5 ,printer) --this is where the delay gets used. |
Now lets add it to your script:
01 | function load () |
02 |
03 | Tool = script.Parent |
04 | Player = game.Players.LocalPlayer |
05 | Camera = game.Workspace.CurrentCamera |
06 | Mouse = Player:GetMouse() |
07 |
08 | local weld 1 = Instance.new( "Weld" ) |
09 | weld 1. Parent = Game.JointsService |
10 | weld 1. C 1 = Player.Character.Head.CFrame:toObjectSpace(Player.Character.Torso.CFrame) |
11 | weld 1. Part 0 = Player.Character.Torso |
12 | weld 1. Part 1 = Player.Character.Head |
13 |
14 | game:GetService( "RunService" ).RenderStepped:connect( function () --What makes the head aim to the mouse |
15 | weld 1. C 1 = CFrame.new(Player.Character.Head.CFrame.p, Mouse.Hit.p):toObjectSpace(Player.Character.Torso.CFrame) |
16 | end ) |
17 |
18 | end |
19 |
20 | delay( 2 , load ) |
HOPE THIS HELPED!