SHOW:
|
|
- or go back to the newest paste.
1 | --https://github.com/Mokiros/roblox-FE-compatibility | |
2 | if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end | |
3 | local Player,game,owner = owner,game | |
4 | local RealPlayer = Player | |
5 | do | |
6 | print("FE Compatibility code V2 by Mokiros") | |
7 | local RealPlayer = RealPlayer | |
8 | script.Parent = RealPlayer.Character | |
9 | ||
10 | --Fake event to make stuff like Mouse.KeyDown work | |
11 | local Disconnect_Function = function(this) | |
12 | this[1].Functions[this[2]] = nil | |
13 | end | |
14 | local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}} | |
15 | local FakeEvent_Metatable = {__index={ | |
16 | Connect = function(this,f) | |
17 | local i = tostring(math.random(0,10000)) | |
18 | while this.Functions[i] do | |
19 | i = tostring(math.random(0,10000)) | |
20 | end | |
21 | this.Functions[i] = f | |
22 | return setmetatable({this,i},Disconnect_Metatable) | |
23 | end | |
24 | }} | |
25 | FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect | |
26 | local function fakeEvent() | |
27 | return setmetatable({Functions={}},FakeEvent_Metatable) | |
28 | end | |
29 | ||
30 | --Creating fake input objects with fake variables | |
31 | local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()} | |
32 | FakeMouse.keyUp = FakeMouse.KeyUp | |
33 | FakeMouse.keyDown = FakeMouse.KeyDown | |
34 | local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()} | |
35 | local CAS = {Actions={},BindAction=function(self,name,fun,touch,...) | |
36 | CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil | |
37 | end} | |
38 | --Merged 2 functions into one by checking amount of arguments | |
39 | CAS.UnbindAction = CAS.BindAction | |
40 | ||
41 | --This function will trigger the events that have been :Connect()'ed | |
42 | local function TriggerEvent(self,ev,...) | |
43 | for _,f in pairs(self[ev].Functions) do | |
44 | f(...) | |
45 | end | |
46 | end | |
47 | FakeMouse.TriggerEvent = TriggerEvent | |
48 | UIS.TriggerEvent = TriggerEvent | |
49 | ||
50 | --Client communication | |
51 | local Event = Instance.new("RemoteEvent") | |
52 | Event.Name = "UserInput_Event" | |
53 | Event.OnServerEvent:Connect(function(plr,io) | |
54 | if plr~=RealPlayer then return end | |
55 | FakeMouse.Target = io.Target | |
56 | FakeMouse.Hit = io.Hit | |
57 | if not io.isMouse then | |
58 | local b = io.UserInputState == Enum.UserInputState.Begin | |
59 | if io.UserInputType == Enum.UserInputType.MouseButton1 then | |
60 | return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up") | |
61 | end | |
62 | if io.UserInputType == Enum.UserInputType.MouseButton2 then | |
63 | return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up") | |
64 | end | |
65 | for _,t in pairs(CAS.Actions) do | |
66 | for _,k in pairs(t.Keys) do | |
67 | if k==io.KeyCode then | |
68 | t.Function(t.Name,io.UserInputState,io) | |
69 | end | |
70 | end | |
71 | end | |
72 | FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower()) | |
73 | UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false) | |
74 | end | |
75 | end) | |
76 | Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event") | |
77 | local Mouse = owner:GetMouse() | |
78 | local UIS = game:GetService("UserInputService") | |
79 | local input = function(io,RobloxHandled) | |
80 | if RobloxHandled then return end | |
81 | --Since InputObject is a client-side instance, we create and pass table instead | |
82 | Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target}) | |
83 | end | |
84 | UIS.InputBegan:Connect(input) | |
85 | UIS.InputEnded:Connect(input) | |
86 | local h,t | |
87 | --Give the server mouse data every second frame, but only if the values changed | |
88 | --If player is not moving their mouse, client won't fire events | |
89 | local HB = game:GetService("RunService").Heartbeat | |
90 | while true do | |
91 | if h~=Mouse.Hit or t~=Mouse.Target then | |
92 | h,t=Mouse.Hit,Mouse.Target | |
93 | Event:FireServer({isMouse=true,Target=t,Hit=h}) | |
94 | end | |
95 | --Wait 2 frames | |
96 | for i=1,2 do | |
97 | HB:Wait() | |
98 | end | |
99 | end]==],script) | |
100 | ||
101 | ----Sandboxed game object that allows the usage of client-side methods and services | |
102 | --Real game object | |
103 | local RealGame = game | |
104 | ||
105 | --Metatable for fake service | |
106 | local FakeService_Metatable = { | |
107 | __index = function(self,k) | |
108 | local s = rawget(self,"_RealService") | |
109 | if s then | |
110 | return typeof(s[k])=="function" | |
111 | and function(_,...)return s[k](s,...)end or s[k] | |
112 | end | |
113 | end, | |
114 | __newindex = function(self,k,v) | |
115 | local s = rawget(self,"_RealService") | |
116 | if s then s[k]=v end | |
117 | end | |
118 | } | |
119 | local function FakeService(t,RealService) | |
120 | t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService | |
121 | return setmetatable(t,FakeService_Metatable) | |
122 | end | |
123 | ||
124 | --Fake game object | |
125 | local FakeGame = { | |
126 | GetService = function(self,s) | |
127 | return rawget(self,s) or RealGame:GetService(s) | |
128 | end, | |
129 | Players = FakeService({ | |
130 | LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player) | |
131 | },"Players"), | |
132 | UserInputService = FakeService(UIS,"UserInputService"), | |
133 | ContextActionService = FakeService(CAS,"ContextActionService"), | |
134 | RunService = FakeService({ | |
135 | _btrs = {}, | |
136 | RenderStepped = RealGame:GetService("RunService").Heartbeat, | |
137 | BindToRenderStep = function(self,name,_,fun) | |
138 | self._btrs[name] = self.Heartbeat:Connect(fun) | |
139 | end, | |
140 | UnbindFromRenderStep = function(self,name) | |
141 | self._btrs[name]:Disconnect() | |
142 | end, | |
143 | },"RunService") | |
144 | } | |
145 | rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer) | |
146 | FakeGame.service = FakeGame.GetService | |
147 | FakeService(FakeGame,game) | |
148 | --Changing owner to fake player object to support owner:GetMouse() | |
149 | game,owner = FakeGame,FakeGame.Players.LocalPlayer | |
150 | end | |
151 | ||
152 | ||
153 | local targetName = game.Players.LocalPlayer.Name | |
154 | local player = game.Players:FindFirstChild(targetName) | |
155 | function putTexture(part, frontF, backF, topF, bottomF, leftF, rightF, className) | |
156 | local faces = {"Front", "Back", "Top", "Bottom", "Left", "Right"} | |
157 | for i,f in pairs(faces) do | |
158 | local decal = Instance.new(className, part) | |
159 | if i == 1 then decal.Texture = frontF decal.Name = f end | |
160 | if i == 2 then decal.Texture = backF or frontF decal.Name = f end | |
161 | if i == 3 then decal.Texture = topF or frontF decal.Name = f end | |
162 | if i == 4 then decal.Texture = bottomF or frontF decal.Name = f end | |
163 | if i == 5 then decal.Texture = leftF or frontF decal.Name = f end | |
164 | if i == 6 then decal.Texture = rightF or frontF decal.Name = f end | |
165 | decal.Face = f | |
166 | end | |
167 | return part | |
168 | end | |
169 | function makeSquare(position, size, color, transparency, parent) | |
170 | local label = Instance.new("TextLabel", parent) | |
171 | label.Text = "" | |
172 | label.BorderSizePixel = 0 | |
173 | label.BackgroundTransparency = transparency | |
174 | label.Position = position | |
175 | label.Size = size | |
176 | label.BackgroundColor3 = color | |
177 | end | |
178 | function putToolBarSlot(position, image) | |
179 | local playerGui = player:FindFirstChild("PlayerGui") | |
180 | if playerGui then | |
181 | local gui = playerGui:FindFirstChild("ToolBar") or Instance.new("ScreenGui", playerGui) | |
182 | gui.Name = "ToolBar" | |
183 | local slot = Instance.new("ImageLabel", gui) | |
184 | slot.Position = position | |
185 | slot.Size = UDim2.new(0, 32, 0, 32) | |
186 | slot.BackgroundTransparency = 1 | |
187 | slot.ImageTransparency = 0 | |
188 | slot.Image = image | |
189 | slot.ZIndex = 2 | |
190 | ||
191 | makeSquare(UDim2.new(0, 0, 0, 0), UDim2.new(0, 32, 0, 32), | |
192 | Color3.new(95/255, 89/255, 76/255), 0, slot) | |
193 | makeSquare(UDim2.new(0, 0, 0, 0), UDim2.new(0, 2, 0, 32), | |
194 | Color3.new(0/255, 0/255, 0/255), 0.5, slot) | |
195 | makeSquare(UDim2.new(0, 2, 0, 0), UDim2.new(0, 30, 0, 2), | |
196 | Color3.new(0/255, 0/255, 0/255), 0.5, slot) | |
197 | makeSquare(UDim2.new(0, -2, 0, -2), UDim2.new(0, 36, 0, 2), | |
198 | Color3.new(106/255, 106/255, 106/255), 0, slot) | |
199 | makeSquare(UDim2.new(0, -2, 0, -2), UDim2.new(0, 2, 0, 36), | |
200 | Color3.new(106/255, 106/255, 106/255), 0, slot) | |
201 | makeSquare(UDim2.new(0, 0, 0, 32), UDim2.new(0, 34, 0, 2), | |
202 | Color3.new(130/255, 130/255, 130/255), 0, slot) | |
203 | makeSquare(UDim2.new(0, 32, 0, 0), UDim2.new(0, 2, 0, 34), | |
204 | Color3.new(130/255, 130/255, 130/255), 0, slot) | |
205 | makeSquare(UDim2.new(0, -4, 0, -2), UDim2.new(0, 2, 0, 38), | |
206 | Color3.new(130/255, 130/255, 130/255), 0, slot) | |
207 | makeSquare(UDim2.new(0, 34, 0, -2), UDim2.new(0, 2, 0, 36), | |
208 | Color3.new(106/255, 106/255, 106/255), 0, slot) | |
209 | makeSquare(UDim2.new(0, -2, 0, 34), UDim2.new(0, 38, 0, 2), | |
210 | Color3.new(106/255, 106/255, 106/255), 0, slot) | |
211 | makeSquare(UDim2.new(0, -4, 0, -4), UDim2.new(0, 40, 0, 2), | |
212 | Color3.new(156/255, 156/255, 156/255), 0, slot) | |
213 | end | |
214 | end | |
215 | function divide(x, d) | |
216 | if x ~= 0 and d ~= 0 then | |
217 | return x/d | |
218 | else | |
219 | return x | |
220 | end | |
221 | end -- so it doesn't divide by zero | |
222 | function getDistance(v1, v2) | |
223 | return math.abs((Vector3.new(math.abs(v2.X - v1.X), math.abs(v2.Y - v1.Y), math.abs(v2.Z - v1.Z))).Magnitude) | |
224 | end | |
225 | function round(x) | |
226 | if x%2 ~= 0.5 then | |
227 | return math.floor(x+0.5) | |
228 | end | |
229 | return x-0.5 | |
230 | end | |
231 | function weldTo(part1, part2) | |
232 | local weld = Instance.new("Weld", part1) | |
233 | weld.Part0 = part1 | |
234 | weld.Part1 = part2 | |
235 | end | |
236 | function getMagnitudeXZ(velocity) | |
237 | return math.abs(velocity.X) + math.abs(velocity.Z) | |
238 | end | |
239 | function placeBlock(block, cFPos) | |
240 | local blockPlaced = Instance.new("Part", workspace) | |
241 | blockPlaced.Material = "Fabric" | |
242 | blockPlaced.Anchored = true | |
243 | blockPlaced.Size = block.size | |
244 | blockPlaced.CFrame = cFPos | |
245 | putTexture(blockPlaced, block.frontTex, block.backTex, | |
246 | block.topTex, block.bottomTex, block.leftTex, block.rightTex, "Texture") | |
247 | return blockPlaced | |
248 | end | |
249 | local toolBar = { | |
250 | Dirt = { | |
251 | size = Vector3.new(2.6, 2.6, 2.6), | |
252 | frontTex = "rbxassetid://179655033", | |
253 | backTex = "rbxassetid://179655033", | |
254 | topTex = "rbxassetid://179655033", | |
255 | bottomTex = "rbxassetid://179655033", | |
256 | leftTex = "rbxassetid://179655033", | |
257 | rightTex = "rbxassetid://179655033" | |
258 | }, | |
259 | Grass = { | |
260 | size = Vector3.new(2.6, 2.6, 2.6), | |
261 | frontTex = "rbxassetid://96430337", | |
262 | backTex = "rbxassetid://96430337", | |
263 | topTex = "rbxassetid://96430265", | |
264 | bottomTex = "rbxassetid://179655033", | |
265 | leftTex = "rbxassetid://96430337", | |
266 | rightTex = "rbxassetid://96430337" | |
267 | }, | |
268 | Stone = { | |
269 | size = Vector3.new(2.6, 2.6, 2.6), | |
270 | frontTex = "rbxassetid://75880927", | |
271 | backTex = "rbxassetid://75880927", | |
272 | topTex = "rbxassetid://75880927", | |
273 | bottomTex = "rbxassetid://75880927", | |
274 | leftTex = "rbxassetid://75880927", | |
275 | rightTex = "rbxassetid://75880927" | |
276 | }, | |
277 | Diamond_Ore = { | |
278 | size = Vector3.new(2.6, 2.6, 2.6), | |
279 | frontTex = "rbxassetid://57928490", | |
280 | backTex = "rbxassetid://57928490", | |
281 | topTex = "rbxassetid://57928490", | |
282 | bottomTex = "rbxassetid://57928490", | |
283 | leftTex = "rbxassetid://57928490", | |
284 | rightTex = "rbxassetid://57928490" | |
285 | }, | |
286 | Diamond_Block = { | |
287 | size = Vector3.new(2.6, 2.6, 2.6), | |
288 | frontTex = "rbxassetid://56749955", | |
289 | backTex = "rbxassetid://56749955", | |
290 | topTex = "rbxassetid://56749955", | |
291 | bottomTex = "rbxassetid://56749955", | |
292 | leftTex = "rbxassetid://56749955", | |
293 | rightTex = "rbxassetid://56749955" | |
294 | }, | |
295 | Wood_Planks = { | |
296 | size = Vector3.new(2.6, 2.6, 2.6), | |
297 | frontTex = "rbxassetid://346201871", | |
298 | backTex = "rbxassetid://346201871", | |
299 | topTex = "rbxassetid://346201871", | |
300 | bottomTex = "rbxassetid://346201871", | |
301 | leftTex = "rbxassetid://346201871", | |
302 | rightTex = "rbxassetid://346201871" | |
303 | }, | |
304 | Oak_Log = { | |
305 | size = Vector3.new(2.6, 2.6, 2.6), | |
306 | frontTex = "rbxassetid://310831812", | |
307 | backTex = "rbxassetid://310831812", | |
308 | topTex = "rbxassetid://152538557", | |
309 | bottomTex = "rbxassetid://152538557", | |
310 | leftTex = "rbxassetid://310831812", | |
311 | rightTex = "rbxassetid://310831812" | |
312 | } | |
313 | } | |
314 | if player then | |
315 | local char = player.Character | |
316 | if char then | |
317 | for _,cM in pairs(char:GetChildren()) do | |
318 | if cM.ClassName == "CharacterMesh" then cM:Destroy() end | |
319 | end | |
320 | ||
321 | --[] | |
322 | local gui = player.PlayerGui:FindFirstChild("ToolBar") or Instance.new("ScreenGui", player.PlayerGui) | |
323 | gui.Name = "ToolBar" | |
324 | ||
325 | makeSquare(UDim2.new(0.5, -166, 1, -111), UDim2.new(0, 364, 0, 44), | |
326 | Color3.new(0/255, 0/255, 0/255), 0, gui) | |
327 | ||
328 | local blocks = {"Dirt", "Grass", "Stone", "Diamond_Ore", "Diamond_Block", "Wood_Planks", "Oak_Log"} | |
329 | for i = 1, 9 do | |
330 | if toolBar[blocks[i]] ~= nil then | |
331 | putToolBarSlot(UDim2.new(0.5, -160 + ((i-1)*40), 1, -105), toolBar[blocks[i]].frontTex) | |
332 | else | |
333 | putToolBarSlot(UDim2.new(0.5, -160 + ((i-1)*40), 1, -105), "") | |
334 | end | |
335 | end | |
336 | ||
337 | local humRootPart = char:WaitForChild("HumanoidRootPart") | |
338 | local head = char:WaitForChild("Head") | |
339 | local torso = char:WaitForChild("Torso") | |
340 | local lArm = char:WaitForChild("Left Arm") | |
341 | local rArm = char:WaitForChild("Right Arm") | |
342 | local lLeg = char:WaitForChild("Left Leg") | |
343 | local rLeg = char:WaitForChild("Right Leg") | |
344 | ||
345 | head.Size = Vector3.new(1.3, 1.3, 1.3) | |
346 | putTexture(head, "rbxassetid://38738031", "rbxassetid://36047330", | |
347 | "rbxassetid://36047341", "rbxassetid://36047347", | |
348 | "rbxassetid://36047323", "rbxassetid://36047315", "Decal") | |
349 | head:WaitForChild("Mesh"):Destroy() | |
350 | head:WaitForChild("face"):Destroy() | |
351 | ||
352 | torso.Size = Vector3.new(1.3, 1.95, 0.65) | |
353 | putTexture(torso, "rbxassetid://38934753", "rbxassetid://38934731", | |
354 | "rbxassetid://38934780", "rbxassetid://38934740", | |
355 | "rbxassetid://38934762", "rbxassetid://38934762", "Decal") | |
356 | ||
357 | lArm.Size = Vector3.new(0.65, 1.95, 0.65) | |
358 | putTexture(lArm, "rbxassetid://38934581", "rbxassetid://38934560", | |
359 | "rbxassetid://38934613", "rbxassetid://38934568", | |
360 | "rbxassetid://38934601", "rbxassetid://38934591", "Decal") | |
361 | ||
362 | rArm.Size = Vector3.new(0.65, 1.95, 0.65) | |
363 | putTexture(rArm, "rbxassetid://38934560", "rbxassetid://38934581", | |
364 | "rbxassetid://38934613", "rbxassetid://38934568", | |
365 | "rbxassetid://38934601", "rbxassetid://38934591", "Decal") | |
366 | ||
367 | lLeg.Size = Vector3.new(0.65, 1.95, 0.65) | |
368 | putTexture(lLeg, "rbxassetid://38936226", "rbxassetid://38936209", | |
369 | "rbxassetid://38934719", "rbxassetid://38934712", | |
370 | "rbxassetid://38936255", "rbxassetid://38936242", "Decal") | |
371 | ||
372 | rLeg.Size = Vector3.new(0.65, 1.95, 0.65) | |
373 | putTexture(rLeg, "rbxassetid://38936209", "rbxassetid://38936226", | |
374 | "rbxassetid://38934719", "rbxassetid://38934712", | |
375 | "rbxassetid://38936242", "rbxassetid://38936255", "Decal") | |
376 | ||
377 | char.Humanoid:ClearAllChildren() | |
378 | char.Animate:Remove() | |
379 | ||
380 | -- now for the real stuff | |
381 | -- | | |
382 | -- | | |
383 | -- V | |
384 | Instance.new("BlockMesh", torso) | |
385 | Instance.new("BlockMesh", lArm) | |
386 | Instance.new("BlockMesh", rArm) | |
387 | Instance.new("BlockMesh", lLeg) | |
388 | Instance.new("BlockMesh", rLeg) | |
389 | ||
390 | local camera = workspace.Camera | |
391 | local camPart = Instance.new("Part", camera) | |
392 | camPart.Size = Vector3.new(0, 0, 0) | |
393 | camPart.CFrame = camera.CFrame | |
394 | camPart.Transparency = 1 | |
395 | ||
396 | --[[local cameraHand = Instance.new("Part", camera) | |
397 | cameraHand.Size = Vector3.new(0.65, 1.95, 0.65) | |
398 | cameraHand.CanCollide = false | |
399 | cameraHand.Anchored = true | |
400 | cameraHand.Name = "CameraHand" | |
401 | putTexture(cameraHand, "rbxassetid://38934560", "rbxassetid://38934581", | |
402 | "rbxassetid://38934613", "rbxassetid://38934568", | |
403 | "rbxassetid://38934601", "rbxassetid://38934591", "Decal") | |
404 | ||
405 | local cameraHandWeld = Instance.new("Motor6D", camPart) | |
406 | cameraHandWeld.Part0 = camPart | |
407 | cameraHandWeld.Part1 = cameraHand | |
408 | cameraHandWeld.C0 = CFrame.new(5, 0, 0) | |
409 | ]]-- | |
410 | ||
411 | local humanoid = char:WaitForChild("Humanoid") | |
412 | humanoid.HipHeight = 0.3 | |
413 | ||
414 | local rootJoint = Instance.new("Motor6D", torso) | |
415 | rootJoint.Name = "RootJoint" | |
416 | rootJoint.Part0 = humRootPart | |
417 | rootJoint.Part1 = torso | |
418 | rootJoint.C1 = CFrame.new(0, 0.05, 0) | |
419 | ||
420 | local neck = Instance.new("Motor6D", torso) | |
421 | neck.Name = "Neck" | |
422 | neck.Part0 = head | |
423 | neck.Part1 = torso | |
424 | ||
425 | local lS = Instance.new("Motor6D", torso) | |
426 | lS.Name = "Left Shoulder" | |
427 | lS.Part0 = lArm | |
428 | lS.Part1 = torso | |
429 | lS.C0 = CFrame.new(-0.325, 0.975, 0) * CFrame.Angles(0, 0, 0) | |
430 | lS.C1 = CFrame.new(0.65, 0.975, 0) | |
431 | ||
432 | local rS = Instance.new("Motor6D", torso) | |
433 | rS.Name = "Right Shoulder" | |
434 | rS.Part0 = rArm | |
435 | rS.Part1 = torso | |
436 | rS.C0 = CFrame.new(-0.325, 0.975, 0) * CFrame.Angles(0, 0, 0) | |
437 | rS.C1 = CFrame.new(-0.65, 0.975, 0) * CFrame.Angles(0, -math.rad(180), 0) | |
438 | ||
439 | local lH = Instance.new("Motor6D", torso) | |
440 | lH.Name = "Left Hip" | |
441 | lH.Part0 = lLeg | |
442 | lH.Part1 = torso | |
443 | lH.C0 = CFrame.new(0, 0.975, 0) | |
444 | lH.C1 = CFrame.new(0.325, -0.975, 0) * CFrame.Angles(0, 0, 0) | |
445 | ||
446 | local rH = Instance.new("Motor6D", torso) | |
447 | rH.Name = "Right Hip" | |
448 | rH.Part0 = rLeg | |
449 | rH.Part1 = torso | |
450 | rH.C0 = CFrame.new(0, 0.975, 0) | |
451 | rH.C1 = CFrame.new(-0.325, -0.975, 0) * CFrame.Angles(0, -math.rad(180), 0) | |
452 | ||
453 | for _,p in pairs(char:GetChildren()) do | |
454 | if p.Name ~= "HumanoidRootPart" and p.ClassName == "Part" then | |
455 | local hit = Instance.new("Part", char) | |
456 | hit.Name = "DamagePart" | |
457 | hit.BrickColor = BrickColor.new("Bright red") | |
458 | hit.Material = "SmoothPlastic" | |
459 | hit.Transparency = 1 | |
460 | hit.Size = Vector3.new(p.Size.X + 0.05, p.Size.Y + 0.05, p.Size.Z + 0.05) | |
461 | hit.CanCollide = false | |
462 | weldTo(hit, p) | |
463 | end | |
464 | end | |
465 | ||
466 | local ticks = 0 | |
467 | local times = 0 | |
468 | ||
469 | local walkAnim = 0 | |
470 | local increaseWalkAnim = 1 | |
471 | ||
472 | local idleAnimRotX = 0 | |
473 | local idleAnimRotZ = 0 | |
474 | local sneaking = 0 | |
475 | ||
476 | local RS = game:GetService("RunService").RenderStepped | |
477 | local Mouse = player:GetMouse() | |
478 | ||
479 | local oldHP = humanoid.Health | |
480 | local damageTime = 0 | |
481 | ||
482 | local punchRotX = 0 | |
483 | local punchRotY = 0 | |
484 | local punchRotZ = 0 | |
485 | local punchSpeed = 0 | |
486 | local punching = 0 | |
487 | local selectedBlock = 8 | |
488 | local punchEnded = 1 | |
489 | local itemOnHand = nil | |
490 | ||
491 | local handItem = Instance.new("Part", char) | |
492 | handItem.Name = "HandItem" | |
493 | handItem.Size = Vector3.new(0.52, 0.52, 0.52) | |
494 | handItem.Transparency = 1 | |
495 | handItem.CanCollide = false | |
496 | ||
497 | local handItemWeld = Instance.new("Weld", char) | |
498 | handItemWeld.Part0 = handItem | |
499 | handItemWeld.Part1 = lArm | |
500 | handItemWeld.C1 = CFrame.new(0, -0.9, -0.6) * CFrame.Angles(math.rad(-10), math.rad(45), 0) | |
501 | ||
502 | local sound = Instance.new("Sound", char) | |
503 | sound.Name = "Hurt" | |
504 | sound.Volume = 10 | |
505 | sound.SoundId = "rbxassetid://535690488" | |
506 | ||
507 | local facesToResize = {"Front", "Back", "Left", "Right", "Bottom", "Top"} | |
508 | Mouse.Button1Down:connect(function() | |
509 | if punchEnded == 1 then punching = 1 end | |
510 | if Mouse.Target then | |
511 | if getDistance(head.CFrame.p, Mouse.Hit.p) <= 10.4 then | |
512 | local humanoid = Mouse.Target.Parent:FindFirstChild("Humanoid") | |
513 | if humanoid then | |
514 | humanoid.Health = humanoid.Health - 10 | |
515 | local parts = Mouse.Target.Parent:GetChildren() | |
516 | for _,p in pairs(parts) do | |
517 | if p.ClassName == "Part" then | |
518 | p.Velocity = Vector3.new(p.Velocity.X + (head.CFrame.lookVector.X * 18), p.Velocity.Y + (head.CFrame.lookVector.Y * 18) + 8, p.Velocity.Z + (head.CFrame.lookVector.Z * 18)) | |
519 | end | |
520 | end | |
521 | return | |
522 | end | |
523 | local x = Mouse.Target.CFrame.p.X | |
524 | local y = Mouse.Target.CFrame.p.Y | |
525 | local z = Mouse.Target.CFrame.p.Z | |
526 | if Mouse.TargetSurface.Name == "Right" then x = x + 2.6 end | |
527 | if Mouse.TargetSurface.Name == "Left" then x = x - 2.6 end | |
528 | if Mouse.TargetSurface.Name == "Top" then y = y + 2.6 end | |
529 | if Mouse.TargetSurface.Name == "Bottom" then y = y - 2.6 end | |
530 | if Mouse.TargetSurface.Name == "Back" then z = z + 2.6 end | |
531 | if Mouse.TargetSurface.Name == "Front" then z = z - 2.6 end | |
532 | if Mouse.Target.Size.X > 2.6 or Mouse.Target.Size.Y > 2.6 or Mouse.Target.Size.Z > 2.6 then | |
533 | x = Mouse.Hit.p.X | |
534 | y = Mouse.Hit.p.Y | |
535 | z = Mouse.Hit.p.Z | |
536 | end | |
537 | -- local x = round(math.abs(mouseX)/2.6)*2.6 | |
538 | -- local y = round(math.abs(mouseY)/2.6)*2.6 | |
539 | -- local z = round(math.abs(mouseZ)/2.6)*2.6 | |
540 | -- if Mouse.Hit.p.X < 0 then x = x * -1 end | |
541 | -- if Mouse.Hit.p.Y < 0 then y = y * -1 end | |
542 | -- if Mouse.Hit.p.Z < 0 then z = z * -1 end | |
543 | if selectedBlock == 0 then | |
544 | local blk = placeBlock(toolBar.Dirt, CFrame.new(x, y, z)) | |
545 | for _,f in pairs(facesToResize) do | |
546 | blk:WaitForChild(f).StudsPerTileU = 2.6 | |
547 | blk:WaitForChild(f).StudsPerTileV = 2.6 | |
548 | end | |
549 | elseif selectedBlock == 1 then | |
550 | local blk = placeBlock(toolBar.Grass, CFrame.new(x, y, z)) | |
551 | for _,f in pairs(facesToResize) do | |
552 | blk:WaitForChild(f).StudsPerTileU = 2.6 | |
553 | blk:WaitForChild(f).StudsPerTileV = 2.6 | |
554 | end | |
555 | elseif selectedBlock == 2 then | |
556 | local blk = placeBlock(toolBar.Stone, CFrame.new(x, y, z)) | |
557 | for _,f in pairs(facesToResize) do | |
558 | blk:WaitForChild(f).StudsPerTileU = 2.6 | |
559 | blk:WaitForChild(f).StudsPerTileV = 2.6 | |
560 | end | |
561 | elseif selectedBlock == 3 then | |
562 | local blk = placeBlock(toolBar.Diamond_Ore, CFrame.new(x, y, z)) | |
563 | for _,f in pairs(facesToResize) do | |
564 | blk:WaitForChild(f).StudsPerTileU = 2.6 | |
565 | blk:WaitForChild(f).StudsPerTileV = 2.6 | |
566 | end | |
567 | elseif selectedBlock == 4 then | |
568 | local blk = placeBlock(toolBar.Diamond_Block, CFrame.new(x, y, z)) | |
569 | for _,f in pairs(facesToResize) do | |
570 | blk:WaitForChild(f).StudsPerTileU = 2.6 | |
571 | blk:WaitForChild(f).StudsPerTileV = 2.6 | |
572 | end | |
573 | elseif selectedBlock == 5 then | |
574 | local blk = placeBlock(toolBar.Wood_Planks, CFrame.new(x, y, z)) | |
575 | for _,f in pairs(facesToResize) do | |
576 | blk:WaitForChild(f).StudsPerTileU = 2.6 | |
577 | blk:WaitForChild(f).StudsPerTileV = 2.6 | |
578 | end | |
579 | elseif selectedBlock == 6 then | |
580 | local blk = placeBlock(toolBar.Oak_Log, CFrame.new(x, y, z)) | |
581 | for _,f in pairs(facesToResize) do | |
582 | blk:WaitForChild(f).StudsPerTileU = 2.6 | |
583 | blk:WaitForChild(f).StudsPerTileV = 2.6 | |
584 | end | |
585 | elseif selectedBlock == 7 or selectedBlock == 8 then | |
586 | if Mouse.Target.Size.X <= 10 and Mouse.Target.Size.Y <= 10 and Mouse.Target.Size.Z <= 10 then | |
587 | Mouse.Target.Parent = nil | |
588 | end | |
589 | end | |
590 | end | |
591 | end | |
592 | end) | |
593 | ||
594 | local hasItemOnHand = 0 | |
595 | local hi = 0 | |
596 | -- selection thingy | |
597 | local selectLabel = Instance.new("TextLabel", gui) | |
598 | selectLabel.Size = UDim2.new(0, 32, 0, 32) | |
599 | selectLabel.Position = UDim2.new(0.5, -160 + (selectedBlock*40), 1, -105) | |
600 | selectLabel.BackgroundTransparency = 0.5 | |
601 | selectLabel.BackgroundColor3 = Color3.new(1, 1, 1) | |
602 | selectLabel.BorderSizePixel = 0 | |
603 | selectLabel.Text = "" | |
604 | selectLabel.ZIndex = 3 | |
605 | -- | |
606 | Mouse.KeyDown:connect(function(key) | |
607 | if key == "q" then | |
608 | sneaking = 1 | |
609 | humanoid.WalkSpeed = humanoid.WalkSpeed / 2 | |
610 | rootJoint.C1 = CFrame.new(0, 0.325, 0) * CFrame.Angles(math.rad(sneaking*45), 0, 0) | |
611 | lH.C0 = CFrame.new(0, 0.975, 0) * CFrame.Angles(-math.rad(sneaking*45), 0, 0) | |
612 | rH.C0 = CFrame.new(0, 0.975, 0) * CFrame.Angles(math.rad(sneaking*45), 0, 0) | |
613 | print("Sneaking...") | |
614 | end | |
615 | if key == "8" then | |
616 | selectedBlock = 7 | |
617 | itemOnHand = nil | |
618 | for _,d in pairs(handItem:GetChildren()) do | |
619 | d:Destroy() | |
620 | end | |
621 | if hasItemOnHand == 1 then hi = 1 end | |
622 | end | |
623 | if key == "9" then | |
624 | selectedBlock = 8 | |
625 | itemOnHand = nil | |
626 | for _,d in pairs(handItem:GetChildren()) do | |
627 | d:Destroy() | |
628 | end | |
629 | if hasItemOnHand == 1 then hi = 1 end | |
630 | end | |
631 | if key == "1" then | |
632 | selectedBlock = 0 | |
633 | itemOnHand = toolBar.Dirt | |
634 | for _,d in pairs(handItem:GetChildren()) do | |
635 | d:Destroy() | |
636 | end | |
637 | putTexture(handItem, itemOnHand.frontTex, itemOnHand.backTex, | |
638 | itemOnHand.topTex, itemOnHand.bottomTex, | |
639 | itemOnHand.leftTex, itemOnHand.rightTex, "Texture") | |
640 | for _,f in pairs(facesToResize) do | |
641 | handItem:WaitForChild(f).StudsPerTileU = 0.52 | |
642 | handItem:WaitForChild(f).StudsPerTileV = 0.52 | |
643 | end | |
644 | end | |
645 | if key == "2" then | |
646 | selectedBlock = 1 | |
647 | itemOnHand = toolBar.Grass | |
648 | for _,d in pairs(handItem:GetChildren()) do | |
649 | d:Destroy() | |
650 | end | |
651 | putTexture(handItem, itemOnHand.frontTex, itemOnHand.backTex, | |
652 | itemOnHand.topTex, itemOnHand.bottomTex, | |
653 | itemOnHand.leftTex, itemOnHand.rightTex, "Texture") | |
654 | for _,f in pairs(facesToResize) do | |
655 | handItem:WaitForChild(f).StudsPerTileU = 0.52 | |
656 | handItem:WaitForChild(f).StudsPerTileV = 0.52 | |
657 | end | |
658 | end | |
659 | if key == "3" then | |
660 | selectedBlock = 2 | |
661 | itemOnHand = toolBar.Stone | |
662 | for _,d in pairs(handItem:GetChildren()) do | |
663 | d:Destroy() | |
664 | end | |
665 | putTexture(handItem, itemOnHand.frontTex, itemOnHand.backTex, | |
666 | itemOnHand.topTex, itemOnHand.bottomTex, | |
667 | itemOnHand.leftTex, itemOnHand.rightTex, "Texture") | |
668 | for _,f in pairs(facesToResize) do | |
669 | handItem:WaitForChild(f).StudsPerTileU = 0.52 | |
670 | handItem:WaitForChild(f).StudsPerTileV = 0.52 | |
671 | end | |
672 | end | |
673 | if key == "4" then | |
674 | selectedBlock = 3 | |
675 | itemOnHand = toolBar.Diamond_Ore | |
676 | for _,d in pairs(handItem:GetChildren()) do | |
677 | d:Destroy() | |
678 | end | |
679 | putTexture(handItem, itemOnHand.frontTex, itemOnHand.backTex, | |
680 | itemOnHand.topTex, itemOnHand.bottomTex, | |
681 | itemOnHand.leftTex, itemOnHand.rightTex, "Texture") | |
682 | for _,f in pairs(facesToResize) do | |
683 | handItem:WaitForChild(f).StudsPerTileU = 0.52 | |
684 | handItem:WaitForChild(f).StudsPerTileV = 0.52 | |
685 | end | |
686 | end | |
687 | if key == "5" then | |
688 | selectedBlock = 4 | |
689 | itemOnHand = toolBar.Diamond_Block | |
690 | for _,d in pairs(handItem:GetChildren()) do | |
691 | d:Destroy() | |
692 | end | |
693 | putTexture(handItem, itemOnHand.frontTex, itemOnHand.backTex, | |
694 | itemOnHand.topTex, itemOnHand.bottomTex, | |
695 | itemOnHand.leftTex, itemOnHand.rightTex, "Texture") | |
696 | for _,f in pairs(facesToResize) do | |
697 | handItem:WaitForChild(f).StudsPerTileU = 0.52 | |
698 | handItem:WaitForChild(f).StudsPerTileV = 0.52 | |
699 | end | |
700 | end | |
701 | if key == "6" then | |
702 | selectedBlock = 5 | |
703 | itemOnHand = toolBar.Wood_Planks | |
704 | for _,d in pairs(handItem:GetChildren()) do | |
705 | d:Destroy() | |
706 | end | |
707 | putTexture(handItem, itemOnHand.frontTex, itemOnHand.backTex, | |
708 | itemOnHand.topTex, itemOnHand.bottomTex, | |
709 | itemOnHand.leftTex, itemOnHand.rightTex, "Texture") | |
710 | for _,f in pairs(facesToResize) do | |
711 | handItem:WaitForChild(f).StudsPerTileU = 0.52 | |
712 | handItem:WaitForChild(f).StudsPerTileV = 0.52 | |
713 | end | |
714 | end | |
715 | if key == "7" then | |
716 | selectedBlock = 6 | |
717 | itemOnHand = toolBar.Oak_Log | |
718 | for _,d in pairs(handItem:GetChildren()) do | |
719 | d:Destroy() | |
720 | end | |
721 | putTexture(handItem, itemOnHand.frontTex, itemOnHand.backTex, | |
722 | itemOnHand.topTex, itemOnHand.bottomTex, | |
723 | itemOnHand.leftTex, itemOnHand.rightTex, "Texture") | |
724 | for _,f in pairs(facesToResize) do | |
725 | handItem:WaitForChild(f).StudsPerTileU = 0.52 | |
726 | handItem:WaitForChild(f).StudsPerTileV = 0.52 | |
727 | end | |
728 | end | |
729 | if (key == "0" or key == "1" or key == "2" | |
730 | or key == "3" or key == "4" or key == "5" | |
731 | or key == "6" or key == "7") and hasItemOnHand == 0 then hi = 1 end | |
732 | selectLabel.Position = UDim2.new(0.5, -160 + ((selectedBlock)*40), 1, -105) | |
733 | end) | |
734 | ||
735 | Mouse.KeyUp:connect(function(key) | |
736 | if key == "q" then | |
737 | sneaking = 0 | |
738 | humanoid.WalkSpeed = humanoid.WalkSpeed * 2 | |
739 | rootJoint.C1 = CFrame.new(0, 0.05, 0) * CFrame.Angles(0, 0, 0) | |
740 | lH.C0 = CFrame.new(0, 0.975, 0) * CFrame.Angles(0, 0, 0) | |
741 | rH.C0 = CFrame.new(0, 0.975, 0) * CFrame.Angles(0, 0, 0) | |
742 | print("Stopped sneaking...") | |
743 | end | |
744 | end) | |
745 | ||
746 | while RS:wait() do | |
747 | if itemOnHand ~= nil then | |
748 | hasItemOnHand = 1 | |
749 | handItem.Transparency = 0 | |
750 | else | |
751 | hasItemOnHand = 0 | |
752 | handItem.Transparency = 1 | |
753 | end | |
754 | if humanoid.Health < oldHP then | |
755 | damageTime = 60 | |
756 | sound:Play() | |
757 | end | |
758 | oldHP = humanoid.Health | |
759 | if damageTime > 0 and humanoid.Health > 0 then | |
760 | for _,p in pairs(char:GetChildren()) do | |
761 | if p.Name ~= "HumanoidRootPart" and p.ClassName == "Part" then | |
762 | if p.Name == "DamagePart" then | |
763 | p.Transparency = 0.5 | |
764 | end | |
765 | end | |
766 | end | |
767 | damageTime = damageTime - 2 | |
768 | if damageTime <= 0 then | |
769 | for _,p in pairs(char:GetChildren()) do | |
770 | if p.Name ~= "HumanoidRootPart" and p.ClassName == "Part" then | |
771 | if p.Name == "DamagePart" then | |
772 | p.Transparency = 1 | |
773 | end | |
774 | end | |
775 | end | |
776 | end | |
777 | end | |
778 | camPart.CFrame = camera.CFrame | |
779 | neck.C1 = CFrame.new(0, 0.975, 0) * CFrame.fromEulerAnglesXYZ(math.rad(sneaking*45), math.rad(camPart.Orientation.Y - torso.Orientation.Y), 0) | |
780 | neck.C0 = CFrame.new(0, -0.65, 0) * CFrame.Angles(-math.rad(camPart.Orientation.X - torso.Orientation.X - (sneaking*45)), 0, 0) | |
781 | ||
782 | if getMagnitudeXZ(torso.Velocity) > 1 then | |
783 | if walkAnim >= 1 then | |
784 | increaseWalkAnim = -1 | |
785 | elseif walkAnim <= -1 then | |
786 | increaseWalkAnim = 1 | |
787 | end | |
788 | walkAnim = walkAnim + (increaseWalkAnim/(10+(sneaking*20))) | |
789 | else | |
790 | walkAnim = 0 | |
791 | end | |
792 | ||
793 | --lH.C0 = CFrame.new(0, 0.975, 0) * CFrame.Angles(-math.rad(sneaking*45), 0, 0) | |
794 | --rH.C0 = CFrame.new(0, 0.975, 0) * CFrame.Angles(math.rad(sneaking*45), 0, 0) | |
795 | lH.C0 = lH.C0:lerp(CFrame.new(0, 0.975, 0) * CFrame.Angles(-math.rad(sneaking*45) + math.rad(damageTime*1.5) + math.rad(walkAnim*getMagnitudeXZ(torso.Velocity)*5/(1+sneaking)), 0, 0), 0.1) | |
796 | rH.C0 = rH.C0:lerp(CFrame.new(0, 0.975, 0) * CFrame.Angles(math.rad(sneaking*45) + math.rad(damageTime*1.5) + math.rad(walkAnim*getMagnitudeXZ(torso.Velocity)*5/(1+sneaking)), 0, 0), 0.1) | |
797 | -- | |
798 | --rootJoint.C0 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0) | |
799 | --print(math.abs(head.Orientation.Y) - math.abs(humRootPart.Orientation.Y)) | |
800 | --if (head.Orientation.Y * 2) - (head.Orientation.Y + torso.Orientation.Y) > 45 then | |
801 | --humRootPart.CFrame = humRootPart.CFrame * CFrame.Angles(0, math.rad(-45 + head.Orientation.Y), 0) | |
802 | --print("-45") | |
803 | --end | |
804 | --if (head.Orientation.Y * 2) - (head.Orientation.Y + torso.Orientation.Y) < -45 then | |
805 | --humRootPart.CFrame = humRootPart.CFrame * CFrame.Angles(0, math.rad(45 + head.Orientation.Y), 0) | |
806 | --print("45") | |
807 | --end | |
808 | ||
809 | --move these arms | |
810 | rootJoint.C1 = rootJoint.C1:lerp(CFrame.new(0, 0.325, 0) * CFrame.Angles(math.rad(sneaking*45), math.rad(punchRotY), 0), 0.2) | |
811 | ||
812 | lS.C0 = lS.C0:lerp(CFrame.new(-0.325, 0.975, 0) * CFrame.Angles(idleAnimRotX/20 + math.rad(-hasItemOnHand*10) + math.rad(punchRotX) + math.rad(damageTime*1.5) + math.rad(walkAnim*getMagnitudeXZ(torso.Velocity)*5/(1+sneaking)), 0, math.rad(punchRotZ) + idleAnimRotZ/20), 0.025+(math.min(1, getMagnitudeXZ(torso.Velocity))/12) + divide(punchSpeed, 6) + hi) | |
813 | rS.C0 = rS.C0:lerp(CFrame.new(-0.325, 0.975, 0) * CFrame.Angles(idleAnimRotX/20 + math.rad(damageTime*1.5) + math.rad(walkAnim*getMagnitudeXZ(torso.Velocity)*5/(1+sneaking)), 0, idleAnimRotZ/20), 0.025+(math.min(1, getMagnitudeXZ(torso.Velocity))/12)) | |
814 | if punching == 1 and punchEnded == 1 then | |
815 | punching = 0 | |
816 | print("steve uses punch!!") | |
817 | local coPunch = coroutine.wrap(function() | |
818 | punchEnded = 0 | |
819 | punchSpeed = 1 | |
820 | punchRotX = -60 | |
821 | punchRotY = -8 | |
822 | punchRotZ = -35 | |
823 | wait(0.075) | |
824 | punchSpeed = 1 | |
825 | punchRotX = -75 | |
826 | punchRotY = 8 | |
827 | punchRotZ = 40 | |
828 | wait(0.075) | |
829 | punchSpeed = 1 | |
830 | punchRotX = -20 | |
831 | punchRotZ = 40 | |
832 | wait(0.075) | |
833 | punchSpeed = 3.5 | |
834 | punchRotX = 0 | |
835 | punchRotY = 0 | |
836 | punchRotZ = 0 | |
837 | punchEnded = 1 | |
838 | wait(0.06) | |
839 | punchSpeed = 0 | |
840 | end) | |
841 | coPunch() | |
842 | end | |
843 | if ticks > 20 then | |
844 | ticks = 0 | |
845 | if times == 0 then | |
846 | times = times + 1 | |
847 | idleAnimRotX = -1 | |
848 | idleAnimRotZ = 0 | |
849 | elseif times == 1 then | |
850 | times = times + 1 | |
851 | idleAnimRotX = -0.75 | |
852 | idleAnimRotZ = -0.75 | |
853 | elseif times == 2 then | |
854 | times = times + 1 | |
855 | idleAnimRotX = 0 | |
856 | idleAnimRotZ = -1 | |
857 | elseif times == 3 then | |
858 | times = times + 1 | |
859 | idleAnimRotX = 0.75 | |
860 | idleAnimRotZ = -0.75 | |
861 | --idleAnimRotX = 0.75 | |
862 | --idleAnimRotZ = -0 | |
863 | elseif times == 4 then | |
864 | times = times + 1 | |
865 | idleAnimRotX = 1 | |
866 | idleAnimRotZ = 0 | |
867 | --idleAnimRotX = 1 | |
868 | --idleAnimRotZ = 0 | |
869 | elseif times == 5 then | |
870 | times = times + 1 | |
871 | idleAnimRotX = 0.75 | |
872 | idleAnimRotZ = 0.75 | |
873 | elseif times == 6 then | |
874 | times = times + 1 | |
875 | idleAnimRotX = 0 | |
876 | idleAnimRotZ = 1 | |
877 | elseif times == 7 then | |
878 | times = 0 | |
879 | idleAnimRotX = -0.75 | |
880 | idleAnimRotZ = 0.75 | |
881 | end | |
882 | end | |
883 | if hi == 1 then hi = 0 end | |
884 | ticks = ticks + 1 | |
885 | end | |
886 | end | |
887 | end |