· 6 years ago · Jun 18, 2019, 10:08 AM
1-- This script has been converted to FE by iPxter
2
3
4if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
5local Player,Mouse,mouse,UserInputService,ContextActionService = owner
6do
7 print("FE Compatibility code by Mokiros | Translated to FE by iPxter")
8 script.Parent = Player.Character
9
10 --RemoteEvent for communicating
11 local Event = Instance.new("RemoteEvent")
12 Event.Name = "UserInput_Event"
13
14 --Fake event to make stuff like Mouse.KeyDown work
15 local function fakeEvent()
16 local t = {_fakeEvent=true,Connect=function(self,f)self.Function=f end}
17 t.connect = t.Connect
18 return t
19 end
20
21 --Creating fake input objects with fake variables
22 local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
23 local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
24 local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
25 CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
26 end}
27 --Merged 2 functions into one by checking amount of arguments
28 CAS.UnbindAction = CAS.BindAction
29
30 --This function will trigger the events that have been :Connect()'ed
31 local function te(self,ev,...)
32 local t = m[ev]
33 if t and t._fakeEvent and t.Function then
34 t.Function(...)
35 end
36 end
37 m.TrigEvent = te
38 UIS.TrigEvent = te
39
40 Event.OnServerEvent:Connect(function(plr,io)
41 if plr~=Player then return end
42 if io.isMouse then
43 m.Target = io.Target
44 m.Hit = io.Hit
45 else
46 local b = io.UserInputState == Enum.UserInputState.Begin
47 if io.UserInputType == Enum.UserInputType.MouseButton1 then
48 return m:TrigEvent(b and "Button1Down" or "Button1Up")
49 end
50 for _,t in pairs(CAS.Actions) do
51 for _,k in pairs(t.Keys) do
52 if k==io.KeyCode then
53 t.Function(t.Name,io.UserInputState,io)
54 end
55 end
56 end
57 m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
58 UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
59 end
60 end)
61 Event.Parent = NLS([==[
62 local Player = game:GetService("Players").LocalPlayer
63 local Event = script:WaitForChild("UserInput_Event")
64
65 local UIS = game:GetService("UserInputService")
66 local input = function(io,a)
67 if a then return end
68 --Since InputObject is a client-side instance, we create and pass table instead
69 Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState})
70 end
71 UIS.InputBegan:Connect(input)
72 UIS.InputEnded:Connect(input)
73
74 local Mouse = Player:GetMouse()
75 local h,t
76 --Give the server mouse data 30 times every second, but only if the values changed
77 --If player is not moving their mouse, client won't fire events
78 while wait(1/30) do
79 if h~=Mouse.Hit or t~=Mouse.Target then
80 h,t=Mouse.Hit,Mouse.Target
81 Event:FireServer({isMouse=true,Target=t,Hit=h})
82 end
83 end]==],Player.Character)
84 Mouse,mouse,UserInputService,ContextActionService = m,m,UIS,CAS
85end
86-- Thanks for using Mod2S by NopeUsername
87local functions = {}
88function sandbox(script, func)
89 local OldEnv = getfenv(func)
90
91 local NewEnv = setmetatable({}, {
92 __index = function(self,k)
93 if k == "script" then
94 return script
95 else
96 return OldEnv[k]
97 end
98 end,
99 })
100
101 setfenv(func, NewEnv)
102 return func
103end
104
105local mas = Instance.new("Model", game:GetService("Lighting"))
106-- DECLARING VARIABLES"
107
108local FollowMouseCameraScriptStarterGui = Instance.new("LocalScript")
109
110-- SETTING PROPERTIES
111
112table.insert(functions, sandbox(FollowMouseCameraScriptStarterGui, function()
113--[[
114 [Head/Waist Follow Mouse/Camera Script.]
115 [Works with both R6 and R15, lets you turn your character's head and waist towards your mouse/camera.]
116 [Scripted by (Unknown), upgraded by OhHeyItsCory.]
117 [I'm not sure who made the original script and the person I found it from definitely didn't make it.]
118 [If you find the original creator, please let me know so I can properly credit them <3]
119 [Anyways, here's a list of what I've added.]
120 [Waist rotation. (Previously, only the head turned.)]
121 [Tweening. (Basically, animating the rotation instead of instantly turning.)]
122 [Full body rotation. (If set to true, rotates the entire body towards the mouse.)]
123 [Specific rotation limits. (The original script used one variable to set the limits of both horizontal and vertical rotation, now there's variables for both limits!)]
124--]]
125
126wait()
127
128--[Pre-Funcs]:
129
130local Ang = CFrame.Angles --[Storing these as variables so I dont have to type them out.]
131local aSin = math.asin
132local aTan = math.atan
133
134--[Constants]:
135
136local Cam = game.Workspace.CurrentCamera
137
138local Plr = owner
139local Body = Plr.Character or Plr.CharacterAdded:wait()
140local Head = Body:WaitForChild("Head")
141local Hum = Body:WaitForChild("Humanoid")
142local Core = Body:WaitForChild("HumanoidRootPart")
143local IsR6 = (Hum.RigType.Value==0) --[Checking if the player is using R15 or R6.]
144local Trso = (IsR6 and Body:WaitForChild("Torso")) or Body:WaitForChild("UpperTorso")
145local Neck = (IsR6 and Trso:WaitForChild("Neck")) or Head:WaitForChild("Neck") --[Once we know the Rig, we know what to find.]
146local Waist = (not IsR6 and Trso:WaitForChild("Waist")) --[R6 doesn't have a waist joint, unfortunately.]
147
148--[[
149 [Whether rotation follows the camera or the mouse.]
150 [Useful with tools if true, but camera tracking runs smoother.]
151--]]
152local MseGuide = false
153--[[
154 [Whether the whole character turns to face the mouse.]
155 [If set to true, MseGuide will be set to true and both HeadHorFactor and BodyHorFactor will be set to 0]
156--]]
157local TurnCharacterToMouse = false
158--[[
159 [Horizontal and Vertical limits for head and body tracking.]
160 [Setting to 0 negates tracking, setting to 1 is normal tracking, and setting to anything higher than 1 goes past real life head/body rotation capabilities.]
161--]]
162local HeadHorFactor = 1
163local HeadVertFactor = 0.6
164local BodyHorFactor = 0.5
165local BodyVertFactor = 0.4
166
167--[[
168 [How fast the body rotates.]
169 [Setting to 0 negates tracking, and setting to 1 is instant rotation. 0.5 is a nice in-between that works with MseGuide on or off.]
170 [Setting this any higher than 1 causes weird glitchy shaking occasionally.]
171--]]
172local UpdateSpeed = 0.5
173
174local NeckOrgnC0 = Neck.C0 --[Get the base C0 to manipulate off of.]
175local WaistOrgnC0 = (not IsR6 and Waist.C0) --[Get the base C0 to manipulate off of.]
176
177--[Setup]:
178
179Neck.MaxVelocity = 1/3
180
181-- Activation]:
182if TurnCharacterToMouse == true then
183 MseGuide = true
184 HeadHorFactor = 0
185 BodyHorFactor = 0
186end
187
188game:GetService("RunService").RenderStepped:Connect(function()
189 local CamCF = Cam.CoordinateFrame
190 if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil then --[Check for the Torso and Head...]
191 local TrsoLV = Trso.CFrame.lookVector
192 local HdPos = Head.CFrame.p
193 if IsR6 and Neck or Neck and Waist then --[Make sure the Neck still exists.]
194 if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then
195 local Dist = nil;
196 local Diff = nil;
197 if not MseGuide then --[If not tracking the Mouse then get the Camera.]
198 Dist = (Head.CFrame.p-CamCF.p).magnitude
199 Diff = Head.CFrame.Y-CamCF.Y
200 if not IsR6 then --[R6 and R15 Neck rotation C0s are different; R15: X axis inverted and Z is now the Y.]
201 Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aSin(Diff/Dist)*HeadVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
202 Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang((aSin(Diff/Dist)*BodyVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
203 else --[R15s actually have the properly oriented Neck CFrame.]
204 Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aSin(Diff/Dist)*HeadVertFactor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor),UpdateSpeed/2)
205 end
206 else
207 local Point = Mouse.Hit.p
208 Dist = (Head.CFrame.p-Point).magnitude
209 Diff = Head.CFrame.Y-Point.Y
210 if not IsR6 then
211 Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aTan(Diff/Dist)*HeadVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
212 Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang(-(aTan(Diff/Dist)*BodyVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
213 else
214 Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aTan(Diff/Dist)*HeadVertFactor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor), UpdateSpeed/2)
215 end
216 end
217 end
218 end
219 end
220 if TurnCharacterToMouse == true then
221 Hum.AutoRotate = false
222 Core.CFrame = Core.CFrame:lerp(CFrame.new(Core.Position, Vector3.new(Mouse.Hit.p.x, Core.Position.Y, Mouse.Hit.p.z)), UpdateSpeed / 2)
223 else
224 Hum.AutoRotate = true
225 end
226end)
227end))
228
229
230
231
232
233
234
235for i,v in ipairs(functions) do
236 spawn(function()
237 pcall(v)
238 end)
239end
240
241for i,v in ipairs(mas:GetChildren()) do
242 v.Parent = workspace
243end
244mas:Destroy()