View difference between Paste ID: VCPyBfEm and dWNtVtH1
SHOW: | | - or go back to the newest paste.
1
--just put this on the top of a script and boom 89% works
2
--note this does not work on big scripts
3
if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
4
local Player,game,owner = owner,game
5
local RealPlayer = Player
6
do
7
    local rp = RealPlayer
8
    script.Parent = rp.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,Functions={},Connect=function(self,f)table.insert(self.Functions,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 then
34
            for _,f in pairs(t.Functions) do
35
                f(...)
36
            end
37
        end
38
    end
39
    m.TrigEvent = te
40
    UIS.TrigEvent = te
41
 
42
    Event.OnServerEvent:Connect(function(plr,io)
43
        if plr~=rp then return end
44
        m.Target = io.Target
45
        m.Hit = io.Hit
46
        if not io.isMouse then
47
            local b = io.UserInputState == Enum.UserInputState.Begin
48
            if io.UserInputType == Enum.UserInputType.MouseButton1 then
49
                return m:TrigEvent(b and "Button1Down" or "Button1Up")
50
            end
51
            for _,t in pairs(CAS.Actions) do
52
                for _,k in pairs(t.Keys) do
53
                    if k==io.KeyCode then
54
                        t.Function(t.Name,io.UserInputState,io)
55
                    end
56
                end
57
            end
58
            m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
59
            UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
60
        end
61
    end)
62
    Event.Parent = NLS([==[
63
    local Player = game:GetService("Players").LocalPlayer
64
    local Event = script:WaitForChild("UserInput_Event")
65
 
66
    local Mouse = Player:GetMouse()
67
    local UIS = game:GetService("UserInputService")
68
    local input = function(io,a)
69
        if a then return end
70
        --Since InputObject is a client-side instance, we create and pass table instead
71
        Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
72
    end
73
    UIS.InputBegan:Connect(input)
74
    UIS.InputEnded:Connect(input)
75
 
76
    local h,t
77
    --Give the server mouse data 30 times every second, but only if the values changed
78
    --If player is not moving their mouse, client won't fire events
79
    while wait(1/30) do
80
        if h~=Mouse.Hit or t~=Mouse.Target then
81
            h,t=Mouse.Hit,Mouse.Target
82
            Event:FireServer({isMouse=true,Target=t,Hit=h})
83
        end
84
    end]==],Player.Character)
85
 
86
    ----Sandboxed game object that allows the usage of client-side methods and services
87
    --Real game object
88
    local _rg = game
89
 
90
    --Metatable for fake service
91
    local fsmt = {
92
        __index = function(self,k)
93
            local s = rawget(self,"_RealService")
94
            if s then return s[k] end
95
        end,
96
        __newindex = function(self,k,v)
97
            local s = rawget(self,"_RealService")
98
            if s then s[k]=v end
99
        end,
100
        __call = function(self,...)
101
            local s = rawget(self,"_RealService")
102
            if s then return s(...) end
103
        end
104
    }
105
    local function FakeService(t,RealService)
106
        t._RealService = typeof(RealService)=="string" and _rg:GetService(RealService) or RealService
107
        return setmetatable(t,fsmt)
108
    end
109
 
110
    --Fake game object
111
    local g = {
112
        GetService = function(self,s)
113
            return self[s]
114
        end,
115
        Players = FakeService({
116
            LocalPlayer = FakeService({GetMouse=function(self)return m end},Player)
117
        },"Players"),
118
        UserInputService = FakeService(UIS,"UserInputService"),
119
        ContextActionService = FakeService(CAS,"ContextActionService"),
120
    }
121
    rawset(g.Players,"localPlayer",g.Players.LocalPlayer)
122
    g.service = g.GetService
123
   
124
    g.RunService = FakeService({
125
        RenderStepped = _rg:GetService("RunService").Heartbeat,
126
        BindToRenderStep = function(self,name,_,fun)
127
            self._btrs[name] = self.Heartbeat:Connect(fun)
128
        end,
129
        UnbindFromRenderStep = function(self,name)
130
            self._btrs[name]:Disconnect()
131
        end,
132
    },"RunService")
133
 
134
    setmetatable(g,{
135
        __index=function(self,s)
136
            return _rg:GetService(s) or typeof(_rg[s])=="function"
137
            and function(_,...)return _rg[s](_rg,...)end or _rg[s]
138
        end,
139
        __newindex = fsmt.__newindex,
140
        __call = fsmt.__call
141
    })
142
    --Changing owner to fake player object to support owner:GetMouse()
143
    game,owner = g,g.Players.LocalPlayer
144
end
145
 
146
 
147
148-
local p=game:service("Players")["Tabby_Cxt"]
148+
local p=game:service("Players")["lafur2"]
149
local lol = Instance.new("Tool",p.Backpack)
150
lol.Name = "LaserGun"
151
lol.TextureId = "http://www.roblox.com/asset?id=130093050"
152
local lol2 = Instance.new("Part",lol)
153
lol2.Name = "Handle"
154
local lol3 = Instance.new("SpecialMesh",lol2)
155
lol3.MeshId = "http://www.roblox.com/asset?id=130099641"
156
lol3.Scale = Vector3.new(0.65, 0.65, 0.65)
157
lol3.TextureId = "http://www.roblox.com/asset?id=130093033"
158
local lol4 = Instance.new("PointLight",lol2)
159
lol4.Color = Color3.new(0, 255, 255)
160
lol4.Range = 6
161
local lol5 = Instance.new("Sound",lol2)
162
lol5.Name = "Fire"
163
lol5.SoundId = "http://www.roblox.com/asset?id=130113322"
164
lol6 = Instance.new("Sound",lol2)
165
lol6.Name = "Reload"
166
lol6.SoundId = "http://www.roblox.com/asset?id=130113370"
167
local lol7 = Instance.new("Sound",lol2)
168
lol7.Name = "HitFade"
169
lol7.SoundId = "http://www.roblox.com/asset?id=130113415"
170
-----------------
171
--| Constants |--
172
-----------------
173
174
local SHOT_SPEED = 100
175
local SHOT_TIME = 1
176
177
local NOZZLE_OFFSET = Vector3.new(0, 0.4, -1.1)
178
179
-----------------
180
--| Variables |--
181
-----------------
182
183
local PlayersService = Game:GetService('Players')
184
local DebrisService = Game:GetService('Debris')
185
186
local Tool = lol
187
local Handle = Tool:WaitForChild('Handle')
188
189
local FireSound = Handle:WaitForChild('Fire')
190
local ReloadSound = Handle:WaitForChild('Reload')
191
local HitFadeSound = Handle:WaitForChild('HitFade')
192
193
local PointLight = Handle:WaitForChild('PointLight')
194
195
local Character = nil
196
local Humanoid = nil
197
local Player = nil
198
199
local BaseShot = nil
200
201
-----------------
202
--| Functions |--
203
-----------------
204
205
-- Returns a character ancestor and its Humanoid, or nil
206
local function FindCharacterAncestor(subject)
207
	if subject and subject ~= Workspace then
208
		local humanoid = subject:FindFirstChild('Humanoid')
209
		if humanoid then
210
			return subject, humanoid
211
		else
212
			return FindCharacterAncestor(subject.Parent)
213
		end
214
	end
215
	return nil
216
end
217
218
-- Removes any old creator tags and applies new ones to the specified target
219
local function ApplyTags(target)
220
	while target:FindFirstChild('creator') do
221
		target.creator:Destroy()
222
	end
223
224
	local creatorTag = Instance.new('ObjectValue')
225
	creatorTag.Value = Player
226
	creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
227
228
	local iconTag = Instance.new('StringValue')
229
	iconTag.Value = Tool.TextureId
230
	iconTag.Name = 'icon'
231
232
	iconTag.Parent = creatorTag
233
	creatorTag.Parent = target
234
	DebrisService:AddItem(creatorTag, 4)
235
end
236
237
-- Returns all objects under instance with Transparency
238
local function GetTransparentsRecursive(instance, partsTable)
239
	local partsTable = partsTable or {}
240
	for _, child in pairs(instance:GetChildren()) do
241
		if child:IsA('BasePart') or child:IsA('Decal') then
242
			table.insert(partsTable, child)
243
		end
244
		GetTransparentsRecursive(child, partsTable)
245
	end
246
	return partsTable
247
end
248
249
local function SelectionBoxify(instance)
250
	local selectionBox = Instance.new('SelectionBox')
251
	selectionBox.Adornee = instance
252
	selectionBox.Color = BrickColor.new('Toothpaste')
253
	selectionBox.Parent = instance
254
	return selectionBox
255
end
256
257
local function Light(instance)
258
	local light = PointLight:Clone()
259
	light.Range = light.Range + 2
260
	light.Parent = instance
261
end
262
263
local function FadeOutObjects(objectsWithTransparency, fadeIncrement)
264
	repeat
265
		local lastObject = nil
266
		for _, object in pairs(objectsWithTransparency) do
267
			object.Transparency = object.Transparency + fadeIncrement
268
			lastObject = object
269
		end
270
		wait()
271
	until lastObject.Transparency >= 1 or not lastObject
272
end
273
274
local function Dematerialize(character, humanoid, firstPart)
275
	humanoid.WalkSpeed = 0
276
277
	local parts = {}
278
	for _, child in pairs(character:GetChildren()) do
279
		if child:IsA('BasePart') then
280
			child.Anchored = true
281
			table.insert(parts, child)
282
		elseif child:IsA('LocalScript') or child:IsA('Script') then
283
			child:Destroy()
284
		end
285
	end
286
287
	local selectionBoxes = {}
288
289
	local firstSelectionBox = SelectionBoxify(firstPart)
290
	Light(firstPart)
291
	wait(0.05)
292
293
	for _, part in pairs(parts) do
294
		if part ~= firstPart then
295
			table.insert(selectionBoxes, SelectionBoxify(part))
296
			Light(part)
297
		end
298
	end
299
300
	local objectsWithTransparency = GetTransparentsRecursive(character)
301
	FadeOutObjects(objectsWithTransparency, 0.1)
302
303
	wait(0.5)
304
305
	humanoid.Health = 0
306
	DebrisService:AddItem(character, 2)
307
308
	local fadeIncrement = 0.05
309
	Delay(0.2, function()
310
		FadeOutObjects({firstSelectionBox}, fadeIncrement)
311
		if character then
312
			character:Destroy()
313
		end
314
	end)
315
	FadeOutObjects(selectionBoxes, fadeIncrement)
316
end
317
318
local function OnTouched(shot, otherPart)
319
	local character, humanoid = FindCharacterAncestor(otherPart)
320
	if character and humanoid and character ~= Character then
321
		ApplyTags(humanoid)
322
		if shot then
323
			local hitFadeSound = shot:FindFirstChild(HitFadeSound.Name)
324
			if hitFadeSound then
325
				hitFadeSound.Parent = humanoid.Torso
326
				hitFadeSound:Play()
327
			end
328
			shot:Destroy()
329
		end
330
		Dematerialize(character, humanoid, otherPart)
331
	end
332
end
333
334
local function OnEquipped()
335
	Character = Tool.Parent
336
	Humanoid = Character:WaitForChild('Humanoid')
337
	Player = PlayersService:GetPlayerFromCharacter(Character)
338
end
339
340
local function OnActivated()
341
	if Tool.Enabled and Humanoid.Health > 0 then
342
		Tool.Enabled = false
343
344
		FireSound:Play()
345
346
		local handleCFrame = Handle.CFrame
347
		local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET)
348
		local shotCFrame = CFrame.new(firingPoint, Humanoid.TargetPoint)
349
350
		local laserShotClone = BaseShot:Clone()
351
		laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
352
		local bodyVelocity = Instance.new('BodyVelocity')
353
		bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
354
		bodyVelocity.Parent = laserShotClone
355
		laserShotClone.Touched:connect(function(otherPart)
356
			OnTouched(laserShotClone, otherPart)
357
		end)
358
		DebrisService:AddItem(laserShotClone, SHOT_TIME)
359
		laserShotClone.Parent = Tool
360
361
		wait(0.6) -- FireSound length
362
363
		ReloadSound:Play()
364
		wait(0.75) -- ReloadSound length
365
366
		Tool.Enabled = true
367
	end
368
end
369
370
local function OnUnequipped()
371
	
372
end
373
374
--------------------
375
--| Script Logic |--
376
--------------------
377
378
BaseShot = Instance.new('Part')
379
BaseShot.Name = 'Effect'
380
BaseShot.FormFactor = Enum.FormFactor.Custom
381
BaseShot.Size = Vector3.new(0.2, 0.2, 3)
382
BaseShot.CanCollide = false
383
BaseShot.BrickColor = BrickColor.new('Toothpaste')
384
SelectionBoxify(BaseShot)
385
Light(BaseShot)
386
HitFadeSound:Clone().Parent = BaseShot
387
388
Tool.Equipped:connect(OnEquipped)
389
Tool.Unequipped:connect(OnUnequipped)
390
Tool.Activated:connect(OnActivated)