Strange LUA Error While Scripting Garry's Mod SWEP - lua

I am currently working on a Garry's Mod SWEP for my friends server. I have been troubleshooting for about 8 hours, when i got this strange error:
line 13: attempt to index global 'SWEP' (a nil value)
stack traceback:
t.lua:13: in main chunk
[C]: ?
not sure what it means, as i am fairly new to LUA.
Here is my whole script (also at codepad):
if SERVER then
SWEP.Weight = 30
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = true
end
if CLIENT then
SWEP.PrintName = "Bill Nye's Test Weapon"
SWEP.Slot = 4
SWEP.SlotPos = 1
end
SWEP.Base = "weapon_base" -- line 13
SWEP.Category = "Bill Nye's Admin Weapons"
SWEP.Author = "Bill Nye The Russian Spy"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModelFlip = true
SWEP.HoldType = "ar2"
SWEP.ViewModel =
{["element_name2"] = { type = "Model", model = "models/XQM/cylinderx2.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(0.027, 4.118, 0.518), angle = Angle(-90.025, -4.764, -0.364), size = Vector(0.167, 0.167, 0.167), color = Color(90, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["element_name4"] = { type = "Model", model = "models/props_lab/huladoll.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(-0.89, 3.947, 1.452), angle = Angle(-86.752, -1.621, -180), size = Vector(0.273, 0.273, 0.273), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["element_name3"] = { type = "Model", model = "models/props_phx/construct/glass/glass_plate1x1.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(0.017, 6.109, 2.431), angle = Angle(0, 0, 0), size = Vector(0.041, 0.041, 0.041), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 3, bodygroup = {} },
["element_name"] = { type = "Model", model = "models/sprops/misc/alphanum/alphanum_plu.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(0.067, 6.19, 2.417), angle = Angle(0, -1.17, 87.662), size = Vector(0.107, 0.107, 0.107), color = Color(255, 0, 0, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {}}
}
SWEP.WorldModel =
{["element_name2"] = { type = "Model", model = "models/XQM/cylinderx2.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.316, 0.736, -4.292), angle = Angle(0, 0, 0), size = Vector(0.167, 0.167, 0.167), color = Color(90, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["element_name4"] = { type = "Model", model = "models/props_lab/huladoll.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.987, 0.634, -5.249), angle = Angle(180, 17.653, 0), size = Vector(0.273, 0.273, 0.273), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["element_name3"] = { type = "Model", model = "models/props_phx/construct/glass/glass_plate1x1.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(12.293, 0.656, -7.63), angle = Angle(88.204, 1.24, 1.22), size = Vector(0.041, 0.041, 0.041), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 3, bodygroup = {} },
["element_name"] = { type = "Model", model = "models/sprops/misc/alphanum/alphanum_plu.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(12.619, 0.646, -7.801), angle = Angle(0, 89.783, 0.244), size = Vector(0.107, 0.107, 0.107), color = Color(255, 0, 0, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {}}
}
SWEP.Primary.Recoil = 0.00
SWEP.Primary.Damage = 1000
SWEP.Primary.NumShots = 1
SWEP.Primary.Spread = 0
SWEP.Primary.Cone = 0
SWEP.Primary.ClipSize = 27
SWEP.Primary.DefaultClip = 100
SWEP.Primary.Ammo = "ar2"
SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 0.1
SWEP.IronSightsPos = Vector(6.099, -13.468, 2.612)
SWEP.IronSightsAng = Vector(3.517, 0, -0)
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
function SWEP:Initialize()
self:SetWeaponHoldType(self.HoldType)
end
function SWEP:PrimaryAttack()
if (self:CanPrimaryAttack()) then
return
end
local Bullet = {}
Bullet.Num = self.Primary.NumShots
Bullet.Src = self.Owner:GetShootPos ()
Bullet.Dir = self.Owner:GetAimVector ()
Bullet.Spread = Vector(self.Primary.Spread, self.Primary.Spread,0)
Bullet.Tracer = 0
Bullet.Damage = self.Primary.Damage
Bullet.AmmoType = self.Primary.Ammo
self:ShootEffects()
self:FireBullets(Bullet)
self:EmitSound ("Weapon_IRifle.Single")
self:TakePrimaryAmmo ( 1 )
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
end
function SWEP:SecondaryAttack()
return false
end

It means:
in your t.lua file on line 13 you point to SWEP value, which is a null value.
Did you call: SWEP:initialize()?
function SWEP:Initialize()
self:SetWeaponHoldType(self.HoldType)
end
check if your value is "local" or if your SWEP value has been initialized.
also check if you remove it before like this: SWEP = nil or not.

Related

What is the problem with my Gradient Descent Algorithm or how its applied?

I've been trying figure out what I have done wrong for many hours, but just can't figure out. I've even looked at other basic Neural Network libraries to make sure that my gradient descent algorithms were correct, but it still isn't working.
I'm trying to teach it XOR but it outputs -
input (0 0) | 0.011441891321516094
input (1 0) | 0.6558508610135193
input (0 1) | 0.6558003273099053
input (1 1) | 0.6563021185296245
after 1000 trainings, so clearly there's something wrong.
The code is written in lua and I created the Neural Network from raw data so you can easily understand how the data is formatted.
- Training code -
math.randomseed(os.time())
local nn = require("NeuralNetwork")
local network = nn.newFromRawData({
["activationFunction"] = "sigmoid",
["learningRate"] = 0.3,
["net"] = {
[1] = {
[1] = {
["value"] = 0
},
[2] = {
["value"] = 0
}
},
[2] = {
[1] = {
["bias"] = 1,
["netInput"] = 0,
["value"] = 0,
["weights"] = {
[1] = 1,
[2] = 1
}
},
[2] = {
["bias"] = 1,
["netInput"] = 0,
["value"] = 0,
["weights"] = {
[1] = 1,
[2] = 1
}
},
[3] = {
["bias"] = 1,
["netInput"] = 0,
["value"] = 0,
["weights"] = {
[1] = 1,
[2] = 1
}
},
[4] = {
["bias"] = 1,
["netInput"] = 0,
["value"] = 0,
["weights"] = {
[1] = 1,
[2] = 1
}
}
},
[3] = {
[1] = {
["bias"] = 1,
["netInput"] = 0,
["value"] = 0,
["weights"] = {
[1] = 1,
[2] = 1,
[3] = 1,
[4] = 1
}
}
}
}
})
attempts = 1000
for i = 1,attempts do
network:backPropagate({0,0},{0})
network:backPropagate({1,0},{1})
network:backPropagate({0,1},{1})
network:backPropagate({1,1},{0})
end
print("Results:")
print("input (0 0) | "..network:feedForward({0,0})[1])
print("input (1 0) | "..network:feedForward({1,0})[1])
print("input (0 1) | "..network:feedForward({0,1})[1])
print("input (1 1) | "..network:feedForward({1,1})[1])
- Library -
local nn = {}
nn.__index = nn
nn.ActivationFunctions = {
sigmoid = function(x) return 1/(1+math.exp(-x/1)) end,
ReLu = function(x) return math.max(0, x) end,
}
nn.Derivatives = {
sigmoid = function(x) return x * (1 - x) end,
ReLu = function(x) return x > 0 and 1 or 0 end,
}
nn.CostFunctions = {
MSE = function(outputs, expected)
local sum = 0
for i = 1, #outputs do
sum += 1/2*(expected[i] - outputs[i])^2
end
return sum/#outputs
end,
}
function nn.new(inputs, outputs, hiddenLayers, neurons, learningRate, activationFunction)
local self = setmetatable({}, nn)
self.learningRate = learningRate or .3
self.activationFunction = activationFunction or "ReLu"
self.net = {}
local net = self.net
local layers = hiddenLayers+2
for i = 1, layers do
net[i] = {}
end
for i = 1, inputs do
net[1][i] = {value = 0}
end
for i = 2, layers-1 do
for x = 1, neurons do
net[i][x] = {netInput = 0, value = 0, bias = math.random()*2-1, weights = {}}
for z = 1, #net[i-1] do
net[i][x].weights[z] = math.random()*2-1
end
end
end
for i = 1, outputs do
net[layers][i] = {netInput = 0, value = 0, bias = math.random()*2-1, weights = {}}
for z = 1, #net[layers-1] do
net[layers][i].weights[z] = math.random()*2-1
end
end
return self
end
function nn.newFromRawData(data)
return setmetatable(data, nn)
end
function nn:feedForward(inputs)
local net = self.net
local activation = self.activationFunction
local layers = #net
local inputLayer = net[1]
local outputLayer = net[layers]
for i = 1, #inputLayer do
inputLayer[i].value = inputs[i]
end
for i = 2, layers do
local layer = net[i]
for x = 1, #layer do
local sum = layer[x].bias
for z = 1, #net[i-1] do
sum += net[i-1][z].value * layer[x].weights[z]
end
layer[x].netInput = sum
layer[x].value = nn.ActivationFunctions[activation](sum)
end
end
local outputs = {}
for i = 1, #outputLayer do
table.insert(outputs, outputLayer[i].value)
end
return outputs
end
function nn:backPropagate(inputs, expected)
local outputs = self:feedForward(inputs)
local net = self.net
local activation = self.activationFunction
local layers = #net
local lr = self.learningRate
local inputLayer = net[1]
local outputLayer = net[layers]
for i = 1, #outputLayer do
local delta = -(expected[i] - outputs[i]) * nn.Derivatives[activation](net[layers][i].value)
outputLayer[i].delta = delta
end
for i = layers-1, 2, -1 do
local layer = net[i]
local nextLayer = net[i+1]
for x = 1, #layer do
local delta = 0
for z = 1, #nextLayer do
delta += nextLayer[z].delta * nextLayer[z].weights[x]
end
layer[x].delta = delta * nn.Derivatives[activation](layer[x].value)
end
end
for i = 2, layers do
local lastLayer = net[i-1]
for x = 1, #net[i] do
net[i][x].bias -= lr * net[i][x].delta
for z = 1, #lastLayer do
net[i][x].weights[z] -= lr * net[i][x].delta * lastLayer[z].value
end
end
end
end
return nn
Any help would be highly appreciated, thanks!
All initial weights must be DIFFERENT numbers, otherwise backpropagation will not work. For example, you can replace 1 with math.random()
Increase number of attempts to 10000
With these modifications, your code works fine:
Results:
input (0 0) | 0.028138230938126
input (1 0) | 0.97809448578087
input (0 1) | 0.97785000216126
input (1 1) | 0.023128477689456

How do i fix attemp to index nil with function in roblox?

I was making a module to make my in-game UI easier to build guis but I got this error when I was testing it: attempt to index nil with 'CreateWindow'
The code:
local FrameLib = {}
local TweenService = game:GetService("TweenService")
function FrameLib:CreateWindow(WindowName)
local UICornerMain = Instance.new("UICorner")
local UIListLayout = Instance.new("UIListLayout")
local cvb3 = Instance.new("ScreenGui")
local Main = Instance.new("Frame")
local Top = Instance.new("Frame")
local UICorner_2 = Instance.new("UICorner")
local Bottom = Instance.new("Frame")
local Close = Instance.new("TextButton")
local UICorner_3 = Instance.new("UICorner")
local Shadow = Instance.new("Folder")
local UmbraShadow = Instance.new("ImageLabel")
local PenumbraShadow = Instance.new("ImageLabel")
local AmbientShadow = Instance.new("ImageLabel")
local UICorner_4 = Instance.new("UICorner")
local Minimize = Instance.new("TextButton")
local UICorner_5 = Instance.new("UICorner")
local Shadow_2 = Instance.new("Folder")
local UmbraShadow_2 = Instance.new("ImageLabel")
local PenumbraShadow_2 = Instance.new("ImageLabel")
local AmbientShadow_2 = Instance.new("ImageLabel")
local TextLabel = Instance.new("TextLabel")
local Pattern = Instance.new("ImageLabel")
local AmbientShadow1 = Instance.new("ImageLabel")
local UIAspectRatioConstraint = Instance.new("UIAspectRatioConstraint")
local AmbientShadow2 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_2 = Instance.new("UIAspectRatioConstraint")
local PenumbraShadow1 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_3 = Instance.new("UIAspectRatioConstraint")
local PenumbraShadow2 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_4 = Instance.new("UIAspectRatioConstraint")
local UmbraShadow1 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_5 = Instance.new("UIAspectRatioConstraint")
local UmbraShadow2 = Instance.new("ImageLabel")
local UIAspectRatioConstraint_6 = Instance.new("UIAspectRatioConstraint")
local Stroke = Instance.new("UIStroke")
local ButtonFrame = Instance.new("ScrollingFrame")
local Sections = Instance.new("Frame")
cvb3.Name = "Main"
cvb3.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
cvb3.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
Main.Name = "Main"
Main.Parent = cvb3
Main.AnchorPoint = Vector2.new(0, 0.5)
Main.BackgroundColor3 = Color3.fromRGB(63, 63, 63)
Main.BorderSizePixel = 0
Main.ClipsDescendants = true
Main.Position = UDim2.new(0.374725521, 0, 0.478996277, 0)
Main.Size = UDim2.new(0, 421, 0, 300)
UICornerMain.CornerRadius = UDim.new(0, 5)
UICornerMain.Parent = Main
Stroke.Name = "Stroke"
Stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Contextual
Stroke.Color = Color3.fromRGB(149,149,149)
Stroke.LineJoinMode = Enum.LineJoinMode.Round
Stroke.Thickness = 1
Stroke.Enabled = true
Stroke.Parent = Main
Top.Name = "Top"
Top.Parent = Main
Top.BackgroundColor3 = Color3.fromRGB(44, 44, 44)
Top.BorderSizePixel = 0
Top.Size = UDim2.new(0, 421, 0, 32)
UICorner_2.CornerRadius = UDim.new(0, 5)
UICorner_2.Parent = Top
Bottom.Name = "Bottom"
Bottom.Parent = Top
Bottom.BackgroundColor3 = Color3.fromRGB(44, 44, 44)
Bottom.BorderSizePixel = 0
Bottom.Position = UDim2.new(0, 0, 0.736249983, 0)
Bottom.Size = UDim2.new(0, 421, 0, 8)
Close.Name = "Close"
Close.Parent = Top
Close.BackgroundColor3 = Color3.fromRGB(38, 38, 38)
Close.BorderSizePixel = 0
Close.Position = UDim2.new(0.914489329, 0, 0.0625, 0)
Close.Selectable = false
Close.Size = UDim2.new(0, 28, 0, 29)
Close.ZIndex = 2
Close.Selected = true
Close.Font = Enum.Font.GothamSemibold
Close.Text = "X"
Close.TextColor3 = Color3.fromRGB(255, 255, 255)
Close.TextSize = 15.000
Close.TextWrapped = true
UICorner_3.CornerRadius = UDim.new(0, 5)
UICorner_3.Parent = Close
Shadow.Name = "Shadow"
Shadow.Parent = Close
UmbraShadow.Name = "UmbraShadow"
UmbraShadow.Parent = Shadow
UmbraShadow.AnchorPoint = Vector2.new(0.5, 0.5)
UmbraShadow.BackgroundTransparency = 1.000
UmbraShadow.BorderSizePixel = 0
UmbraShadow.Position = UDim2.new(0.5, 0, 0.5, 6)
UmbraShadow.Size = UDim2.new(1, 10, 1, 10)
UmbraShadow.Image = "rbxassetid://1316045217"
UmbraShadow.ImageColor3 = Color3.fromRGB(0, 0, 0)
UmbraShadow.ImageTransparency = 0.860
UmbraShadow.ScaleType = Enum.ScaleType.Slice
UmbraShadow.SliceCenter = Rect.new(10, 10, 118, 118)
PenumbraShadow.Name = "PenumbraShadow"
PenumbraShadow.Parent = Shadow
PenumbraShadow.AnchorPoint = Vector2.new(0.5, 0.5)
PenumbraShadow.BackgroundTransparency = 1.000
PenumbraShadow.BorderSizePixel = 0
PenumbraShadow.Position = UDim2.new(0.5, 0, 0.5, 1)
PenumbraShadow.Size = UDim2.new(1, 18, 1, 18)
PenumbraShadow.Image = "rbxassetid://1316045217"
PenumbraShadow.ImageColor3 = Color3.fromRGB(0, 0, 0)
PenumbraShadow.ImageTransparency = 0.880
PenumbraShadow.ScaleType = Enum.ScaleType.Slice
PenumbraShadow.SliceCenter = Rect.new(10, 10, 118, 118)
AmbientShadow.Name = "AmbientShadow"
AmbientShadow.Parent = Shadow
AmbientShadow.AnchorPoint = Vector2.new(0.5, 0.5)
AmbientShadow.BackgroundTransparency = 1.000
AmbientShadow.BorderSizePixel = 0
AmbientShadow.Position = UDim2.new(0.5, 0, 0.5, 3)
AmbientShadow.Size = UDim2.new(1, 5, 1, 5)
AmbientShadow.Image = "rbxassetid://1316045217"
AmbientShadow.ImageColor3 = Color3.fromRGB(0, 0, 0)
AmbientShadow.ImageTransparency = 0.800
AmbientShadow.ScaleType = Enum.ScaleType.Slice
AmbientShadow.SliceCenter = Rect.new(10, 10, 118, 118)
UICorner_4.CornerRadius = UDim.new(0, 5)
UICorner_4.Parent = Top
Minimize.Name = "Minimize"
Minimize.Parent = Top
Minimize.BackgroundColor3 = Color3.fromRGB(38, 38, 38)
Minimize.BorderSizePixel = 0
Minimize.Position = UDim2.new(0.831353962, 0, 0.0625, 0)
Minimize.Size = UDim2.new(0, 28, 0, 29)
Minimize.ZIndex = 2
Minimize.Font = Enum.Font.GothamSemibold
Minimize.Text = "-"
Minimize.TextColor3 = Color3.fromRGB(255, 255, 255)
Minimize.TextSize = 15.000
Minimize.TextWrapped = true
UICorner_5.CornerRadius = UDim.new(0, 5)
UICorner_5.Parent = Minimize
Shadow_2.Name = "Shadow"
Shadow_2.Parent = Minimize
UmbraShadow_2.Name = "UmbraShadow"
UmbraShadow_2.Parent = Shadow_2
UmbraShadow_2.AnchorPoint = Vector2.new(0.5, 0.5)
UmbraShadow_2.BackgroundTransparency = 1.000
UmbraShadow_2.BorderSizePixel = 0
UmbraShadow_2.Position = UDim2.new(0.5, 0, 0.5, 6)
UmbraShadow_2.Size = UDim2.new(1, 10, 1, 10)
UmbraShadow_2.Image = "rbxassetid://1316045217"
UmbraShadow_2.ImageColor3 = Color3.fromRGB(0, 0, 0)
UmbraShadow_2.ImageTransparency = 0.860
UmbraShadow_2.ScaleType = Enum.ScaleType.Slice
UmbraShadow_2.SliceCenter = Rect.new(10, 10, 118, 118)
PenumbraShadow_2.Name = "PenumbraShadow"
PenumbraShadow_2.Parent = Shadow_2
PenumbraShadow_2.AnchorPoint = Vector2.new(0.5, 0.5)
PenumbraShadow_2.BackgroundTransparency = 1.000
PenumbraShadow_2.BorderSizePixel = 0
PenumbraShadow_2.Position = UDim2.new(0.5, 0, 0.5, 1)
PenumbraShadow_2.Size = UDim2.new(1, 18, 1, 18)
PenumbraShadow_2.Image = "rbxassetid://1316045217"
PenumbraShadow_2.ImageColor3 = Color3.fromRGB(0, 0, 0)
PenumbraShadow_2.ImageTransparency = 0.880
PenumbraShadow_2.ScaleType = Enum.ScaleType.Slice
PenumbraShadow_2.SliceCenter = Rect.new(10, 10, 118, 118)
AmbientShadow_2.Name = "AmbientShadow"
AmbientShadow_2.Parent = Shadow_2
AmbientShadow_2.AnchorPoint = Vector2.new(0.5, 0.5)
AmbientShadow_2.BackgroundTransparency = 1.000
AmbientShadow_2.BorderSizePixel = 0
AmbientShadow_2.Position = UDim2.new(0.5, 0, 0.5, 3)
AmbientShadow_2.Size = UDim2.new(1, 5, 1, 5)
AmbientShadow_2.Image = "rbxassetid://1316045217"
AmbientShadow_2.ImageColor3 = Color3.fromRGB(0, 0, 0)
AmbientShadow_2.ImageTransparency = 0.800
AmbientShadow_2.ScaleType = Enum.ScaleType.Slice
AmbientShadow_2.SliceCenter = Rect.new(10, 10, 118, 118)
TextLabel.Parent = Top
TextLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
TextLabel.BackgroundTransparency = 1.000
TextLabel.Position = UDim2.new(0.0190023743, 0, 0.1875, 0)
TextLabel.Size = UDim2.new(0, 200, 0, 21)
TextLabel.Font = Enum.Font.GothamSemibold
TextLabel.Text = WindowName
TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
TextLabel.TextScaled = true
TextLabel.TextSize = 14.000
TextLabel.TextWrapped = true
TextLabel.TextXAlignment = Enum.TextXAlignment.Left
TextLabel.TextYAlignment = Enum.TextYAlignment.Top
Pattern.Name = "Pattern"
Pattern.Parent = Main
Pattern.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Pattern.BackgroundTransparency = 1.000
Pattern.Position = UDim2.new(-0.124703087, 0, -0.146666661, 0)
Pattern.Size = UDim2.new(0, 504, 0, 372)
Pattern.ZIndex = 0
Pattern.Image = "rbxassetid://2151741365"
Pattern.ImageTransparency = 0.400
Pattern.ScaleType = Enum.ScaleType.Tile
Pattern.SliceCenter = Rect.new(0, 256, 0, 256)
Pattern.TileSize = UDim2.new(0, 250, 0, 250)
AmbientShadow1.Name = "AmbientShadow1"
AmbientShadow1.Parent = cvb3
AmbientShadow1.AnchorPoint = Vector2.new(0.5, 0.5)
AmbientShadow1.BackgroundTransparency = 1.000
AmbientShadow1.BorderSizePixel = 0
AmbientShadow1.Position = UDim2.new(0.509783506, 0, 0.481963903, 3)
AmbientShadow1.Size = UDim2.new(0, 430, 0, 310)
AmbientShadow1.ZIndex = 0
AmbientShadow1.Image = "rbxassetid://1316045217"
AmbientShadow1.ImageColor3 = Color3.fromRGB(0, 0, 0)
AmbientShadow1.ImageTransparency = 0.800
AmbientShadow1.ScaleType = Enum.ScaleType.Slice
AmbientShadow1.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint.Parent = AmbientShadow1
UIAspectRatioConstraint.AspectRatio = 1.386
AmbientShadow2.Name = "AmbientShadow2"
AmbientShadow2.Parent = cvb3
AmbientShadow2.AnchorPoint = Vector2.new(0.5, 0.5)
AmbientShadow2.BackgroundTransparency = 1.000
AmbientShadow2.BorderSizePixel = 0
AmbientShadow2.Position = UDim2.new(0.509783506, 0, 0.481963903, 3)
AmbientShadow2.Size = UDim2.new(0, 430, 0, 310)
AmbientShadow2.ZIndex = 0
AmbientShadow2.Image = "rbxassetid://1316045217"
AmbientShadow2.ImageColor3 = Color3.fromRGB(0, 0, 0)
AmbientShadow2.ImageTransparency = 0.800
AmbientShadow2.ScaleType = Enum.ScaleType.Slice
AmbientShadow2.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_2.Parent = AmbientShadow2
UIAspectRatioConstraint_2.AspectRatio = 1.386
PenumbraShadow1.Name = "PenumbraShadow1"
PenumbraShadow1.Parent = cvb3
PenumbraShadow1.AnchorPoint = Vector2.new(0.5, 0.5)
PenumbraShadow1.BackgroundTransparency = 1.000
PenumbraShadow1.BorderSizePixel = 0
PenumbraShadow1.Position = UDim2.new(0.509274423, 0, 0.48696661, 1)
PenumbraShadow1.Size = UDim2.new(0, 431, 0, 309)
PenumbraShadow1.ZIndex = 0
PenumbraShadow1.Image = "rbxassetid://1316045217"
PenumbraShadow1.ImageColor3 = Color3.fromRGB(0, 0, 0)
PenumbraShadow1.ImageTransparency = 0.880
PenumbraShadow1.ScaleType = Enum.ScaleType.Slice
PenumbraShadow1.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_3.Parent = PenumbraShadow1
UIAspectRatioConstraint_3.AspectRatio = 1.398
PenumbraShadow2.Name = "PenumbraShadow2"
PenumbraShadow2.Parent = cvb3
PenumbraShadow2.AnchorPoint = Vector2.new(0.5, 0.5)
PenumbraShadow2.BackgroundTransparency = 1.000
PenumbraShadow2.BorderSizePixel = 0
PenumbraShadow2.Position = UDim2.new(0.509274423, 0, 0.48696661, 1)
PenumbraShadow2.Size = UDim2.new(0, 431, 0, 309)
PenumbraShadow2.ZIndex = 0
PenumbraShadow2.Image = "rbxassetid://1316045217"
PenumbraShadow2.ImageColor3 = Color3.fromRGB(0, 0, 0)
PenumbraShadow2.ImageTransparency = 0.880
PenumbraShadow2.ScaleType = Enum.ScaleType.Slice
PenumbraShadow2.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_4.Parent = PenumbraShadow2
UIAspectRatioConstraint_4.AspectRatio = 1.398
UmbraShadow1.Name = "UmbraShadow1"
UmbraShadow1.Parent = cvb3
UmbraShadow1.AnchorPoint = Vector2.new(0.5, 0.5)
UmbraShadow1.BackgroundTransparency = 1.000
UmbraShadow1.BorderSizePixel = 0
UmbraShadow1.Position = UDim2.new(0.509783506, 0, 0.478506416, 6)
UmbraShadow1.Size = UDim2.new(0, 430, 0, 308)
UmbraShadow1.ZIndex = 0
UmbraShadow1.Image = "rbxassetid://1316045217"
UmbraShadow1.ImageColor3 = Color3.fromRGB(0, 0, 0)
UmbraShadow1.ImageTransparency = 0.860
UmbraShadow1.ScaleType = Enum.ScaleType.Slice
UmbraShadow1.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_5.Parent = UmbraShadow1
UIAspectRatioConstraint_5.AspectRatio = 1.395
UmbraShadow2.Name = "UmbraShadow2"
UmbraShadow2.Parent = cvb3
UmbraShadow2.AnchorPoint = Vector2.new(0.5, 0.5)
UmbraShadow2.BackgroundTransparency = 1.000
UmbraShadow2.BorderSizePixel = 0
UmbraShadow2.Position = UDim2.new(0.509783506, 0, 0.478506416, 6)
UmbraShadow2.Size = UDim2.new(0, 430, 0, 308)
UmbraShadow2.ZIndex = 0
UmbraShadow2.Image = "rbxassetid://1316045217"
UmbraShadow2.ImageColor3 = Color3.fromRGB(0, 0, 0)
UmbraShadow2.ImageTransparency = 0.860
UmbraShadow2.ScaleType = Enum.ScaleType.Slice
UmbraShadow2.SliceCenter = Rect.new(10, 10, 118, 118)
UIAspectRatioConstraint_6.Parent = UmbraShadow2
UIAspectRatioConstraint_6.AspectRatio = 1.395
ButtonFrame.Name = "ButtonFrame"
ButtonFrame.Parent = Main
ButtonFrame.Active = true
ButtonFrame.BackgroundColor3 = Color3.fromRGB(44, 44, 44)
ButtonFrame.BorderSizePixel = 0
ButtonFrame.Position = UDim2.new(0, 0, 0.106666669, 0)
ButtonFrame.Size = UDim2.new(0, 88, 0, 268)
ButtonFrame.ScrollBarThickness = 0
UIListLayout.HorizontalAlignment = Enum.HorizontalAlignment.Left
UIListLayout.Parent = ButtonFrame
AmbientShadow.Parent = Main
AmbientShadow1.Parent = Main
AmbientShadow2.Parent = Main
PenumbraShadow.Parent = Main
PenumbraShadow1.Parent = Main
PenumbraShadow2.Parent = Main
UmbraShadow.Parent = Main
UmbraShadow1.Parent = Main
UmbraShadow2.Parent = Main
AmbientShadow.Position = UDim2.new(0.498, 0,0.506, 3)
AmbientShadow1.Position = UDim2.new(0.498, 0,0.506, 3)
AmbientShadow2.Position = UDim2.new(0.498, 0,0.506, 3)
PenumbraShadow.Position = UDim2.new(0.498, 0,0.506, 3)
PenumbraShadow1.Position = UDim2.new(0.498, 0,0.506, 3)
PenumbraShadow2.Position = UDim2.new(0.498, 0,0.506, 3)
UmbraShadow.Position = UDim2.new(0.498, 0,0.506, 3)
UmbraShadow1.Position = UDim2.new(0.498, 0,0.506, 3)
UmbraShadow2.Position = UDim2.new(0.498, 0,0.506, 3)
AmbientShadow.ZIndex = -1
AmbientShadow1.ZIndex = -1
AmbientShadow2.ZIndex = -1
PenumbraShadow.ZIndex = -1
PenumbraShadow1.ZIndex = -1
PenumbraShadow2.ZIndex = -1
UmbraShadow.ZIndex = -1
UmbraShadow1.ZIndex = -1
UmbraShadow2.ZIndex = -1
Sections.Name = "Sections"
Sections.Parent = Main
Sections.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Sections.BackgroundTransparency = 1.000
Sections.Position = UDim2.new(0.211401418, 0, 0.109999999, 0)
Sections.Size = UDim2.new(0, 332, 0, 267)
local PatStroke = Instance.new("UIStroke")
local PatCorner = Instance.new("UICorner")
PatCorner.Parent = Pattern
PatCorner.CornerRadius = UDim.new(0,5)
PatStroke.Parent = Pattern
PatStroke.Color = Color3.fromRGB(149, 149, 149)
PatStroke.LineJoinMode = Enum.LineJoinMode.Round
Pattern.ZIndex = 0
Pattern.BackgroundColor3 = Color3.fromRGB(63, 63, 63)
Pattern.BackgroundTransparency = 0
end
I was searching about this error with a function but I couldn't find any so I'm trying if here I can get any help about this error because I have been working very hard on this to make my GUI easier to build but well it's now struggling me to find any solutions.
The error is not in the provided code.
It must be something where you do.
someVariable["CreateWindow"], someVariable.CreateWindow or someVariable:CreateWindow() where someVariable is a nil value. Indexing nil values is not allowed.
You failed to refer that variable to your FrameLib table. Maybe just a typo? Lua errors typically come with a stack trace that provides you with information about which line of which file cause the error together with the sequence of function calls that lead to that error.
If you don't know the three possible indexing operations in Lua and hence what to look for in this case you probably should revisit the basics of Lua befor doing any further Roblox development.

What does this error mean? I cannot seem to get this code to work

Im trying to get this lua code to run but cannot seem to get it to work. Whenever i run it i get this error that i cant seem to avoid no matter how many times i edit it.
Can anybody find a solution for this? I have been searching all over the web to no avail.
This is the error i get
input:58: unexpected symbol near eof
Here is the code:
-- Made By Vincent
local ScreenGui = Instance.new("ScreenGui")
local Main = Instance.new("Frame")
local RoundedCorners = Instance.new("UICorner")
local BlackHoleGun = Instance.new("TextButton")
local UICorner = Instance.new("UICorner")
local GoldenPistol = Instance.new("TextButton")
local UICorner_2 = Instance.new("UICorner")
local CrazyFuturisticMinigun = Instance.new("TextButton")
local UICorner_3 = Instance.new("UICorner")
local BiochemicalBlaster = Instance.new("TextButton")
local UICorner_4 = Instance.new("UICorner")
local SpaceRifle = Instance.new("TextButton")
local UICorner_5 = Instance.new("UICorner")
local LavaPistol = Instance.new("TextButton")
local UICorner_6 = Instance.new("UICorner")
local Scar = Instance.new("TextButton")
local UICorner_7 = Instance.new("UICorner")
local RayGun = Instance.new("TextButton")
local UICorner_8 = Instance.new("UICorner")
local SniperRifle = Instance.new("TextButton")
local UICorner_9 = Instance.new("UICorner")
--Properties:
ScreenGui.Parent = game.CoreGui
Main.Name = "Main"
Main.Parent = ScreenGui
Main.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Main.Position = UDim2.new(0.383399218, 0, 0.121621616, 0)
Main.Size = UDim2.new(0, 426, 0, 211)
Main.Active = true
Main.Draggable = true
RoundedCorners.Name = "RoundedCorners"
RoundedCorners.Parent = Main
BlackHoleGun.Name = "Black Hole Gun"
BlackHoleGun.Parent = ScreenGui
BlackHoleGun.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
BlackHoleGun.Position = UDim2.new(0.393280655, 0, 0.136486486, 0)
BlackHoleGun.Size = UDim2.new(0, 121, 0, 49)
BlackHoleGun.Font = Enum.Font.GothamBold
BlackHoleGun.Text = "Black Hole Gun"
BlackHoleGun.TextColor3 = Color3.fromRGB(255, 219, 0)
BlackHoleGun.TextScaled = true
BlackHoleGun.TextSize = 14.000
BlackHoleGun.TextStrokeColor3 = Color3.fromRGB(174, 38, 148)
BlackHoleGun.TextWrapped = true
BlackHoleGun.MouseButton1Down:connect(function()
local Remote = game.Workspace.__THINGS.__REMOTES['weaponequipped']
local Arguments = {
[1] = {
[1] = {
[1] = "Black Hole Gun"
},
[2] = {
[1] = false
}
}
}
Remote:FireServer(unpack(Arguments))
UICorner.Parent = BlackHoleGun
GoldenPistol.Name = "Golden Pistol"
GoldenPistol.Parent = ScreenGui
GoldenPistol.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
GoldenPistol.Position = UDim2.new(0.533596873, 0, 0.136486486, 0)
GoldenPistol.Size = UDim2.new(0, 121, 0, 49)
GoldenPistol.Font = Enum.Font.GothamBold
GoldenPistol.Text = "Golden Pistol"
GoldenPistol.TextColor3 = Color3.fromRGB(255, 219, 0)
GoldenPistol.TextScaled = true
GoldenPistol.TextSize = 14.000
GoldenPistol.TextStrokeColor3 = Color3.fromRGB(174, 38, 148)
GoldenPistol.TextWrapped = true
NAMEOFBUTTONHERE.MouseButton1Down:connect(function()
local Remote = game.Workspace.__THINGS.__REMOTES['weaponequipped']
local Arguments = {
[1] = {
[1] = {
[1] = "Golden Pistol"
},
[2] = {
[1] = false
}
}
}
Remote:FireServer(unpack(Arguments))
end)
UICorner_2.Parent = GoldenPistol
CrazyFuturisticMinigun.Name = "Crazy Futuristic Minigun"
CrazyFuturisticMinigun.Parent = ScreenGui
CrazyFuturisticMinigun.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
CrazyFuturisticMinigun.Position = UDim2.new(0.673913062, 0, 0.136486486, 0)
CrazyFuturisticMinigun.Size = UDim2.new(0, 121, 0, 49)
CrazyFuturisticMinigun.Font = Enum.Font.GothamBold
CrazyFuturisticMinigun.Text = "Crazy Futuristic Minigun"
CrazyFuturisticMinigun.TextColor3 = Color3.fromRGB(255, 219, 0)
CrazyFuturisticMinigun.TextScaled = true
CrazyFuturisticMinigun.TextSize = 14.000
CrazyFuturisticMinigun.TextStrokeColor3 = Color3.fromRGB(174, 38, 148)
CrazyFuturisticMinigun.TextWrapped = true
NAMEOFBUTTONHERE.MouseButton1Down:connect(function()
local Remote = game.Workspace.__THINGS.__REMOTES['weaponequipped']
local Arguments = {
[1] = {
[1] = {
[1] = "Crazy Futuristic Minigun"
},
[2] = {
[1] = false
}
}
}
Remote:FireServer(unpack(Arguments))
end)
UICorner_3.Parent = CrazyFuturisticMinigun
BiochemicalBlaster.Name = "Biochemical Blaster"
BiochemicalBlaster.Parent = ScreenGui
BiochemicalBlaster.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
BiochemicalBlaster.Position = UDim2.new(0.393280655, 0, 0.231081083, 0)
BiochemicalBlaster.Size = UDim2.new(0, 121, 0, 49)
BiochemicalBlaster.Font = Enum.Font.GothamBold
BiochemicalBlaster.Text = "Biochemical Blaster"
BiochemicalBlaster.TextColor3 = Color3.fromRGB(255, 219, 0)
BiochemicalBlaster.TextScaled = true
BiochemicalBlaster.TextSize = 14.000
BiochemicalBlaster.TextStrokeColor3 = Color3.fromRGB(174, 38, 148)
BiochemicalBlaster.TextWrapped = true
NAMEOFBUTTONHERE.MouseButton1Down:connect(function()
local Remote = game.Workspace.__THINGS.__REMOTES['weaponequipped']
local Arguments = {
[1] = {
[1] = {
[1] = "Biochemical Blaster"
},
[2] = {
[1] = false
}
}
}
Remote:FireServer(unpack(Arguments))
end)
UICorner_4.Parent = BiochemicalBlaster
SpaceRifle.Name = "Space Rifle"
SpaceRifle.Parent = ScreenGui
SpaceRifle.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
SpaceRifle.Position = UDim2.new(0.533596873, 0, 0.231081083, 0)
SpaceRifle.Size = UDim2.new(0, 121, 0, 49)
SpaceRifle.Font = Enum.Font.GothamBold
SpaceRifle.Text = "Space Rifle"
SpaceRifle.TextColor3 = Color3.fromRGB(255, 219, 0)
SpaceRifle.TextScaled = true
SpaceRifle.TextSize = 14.000
SpaceRifle.TextStrokeColor3 = Color3.fromRGB(174, 38, 148)
SpaceRifle.TextWrapped = true
NAMEOFBUTTONHERE.MouseButton1Down:connect(function()
local Remote = game.Workspace.__THINGS.__REMOTES['weaponequipped']
local Arguments = {
[1] = {
[1] = {
[1] = "Space Rifle"
},
[2] = {
[1] = false
}
}
}
Remote:FireServer(unpack(Arguments))
end)
UICorner_5.Parent = SpaceRifle
LavaPistol.Name = "Lava Pistol"
LavaPistol.Parent = ScreenGui
LavaPistol.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
LavaPistol.Position = UDim2.new(0.672924936, 0, 0.231081083, 0)
LavaPistol.Size = UDim2.new(0, 121, 0, 49)
LavaPistol.Font = Enum.Font.GothamBold
LavaPistol.Text = "Lava Pistol"
LavaPistol.TextColor3 = Color3.fromRGB(255, 219, 0)
LavaPistol.TextScaled = true
LavaPistol.TextSize = 14.000
LavaPistol.TextStrokeColor3 = Color3.fromRGB(174, 38, 148)
LavaPistol.TextWrapped = true
NAMEOFBUTTONHERE.MouseButton1Down:connect(function()
local Remote = game.Workspace.__THINGS.__REMOTES['weaponequipped']
local Arguments = {
[1] = {
[1] = {
[1] = "Lava Pistol"
},
[2] = {
[1] = false
}
}
}
Remote:FireServer(unpack(Arguments))
end)
UICorner_6.Parent = LavaPistol
Scar.Name = "Scar"
Scar.Parent = ScreenGui
Scar.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
Scar.Position = UDim2.new(0.392292529, 0, 0.322972983, 0)
Scar.Size = UDim2.new(0, 121, 0, 49)
Scar.Font = Enum.Font.GothamBold
Scar.Text = "Scar"
Scar.TextColor3 = Color3.fromRGB(255, 219, 0)
Scar.TextScaled = true
Scar.TextSize = 14.000
Scar.TextStrokeColor3 = Color3.fromRGB(174, 38, 148)
Scar.TextWrapped = true
NAMEOFBUTTONHERE.MouseButton1Down:connect(function()
local Remote = game.Workspace.__THINGS.__REMOTES['weaponequipped']
local Arguments = {
[1] = {
[1] = {
[1] = "SCAR"
},
[2] = {
[1] = false
}
}
}
Remote:FireServer(unpack(Arguments))
end)
UICorner_7.Parent = Scar
RayGun.Name = "Ray Gun"
RayGun.Parent = ScreenGui
RayGun.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
RayGun.Position = UDim2.new(0.533596873, 0, 0.322972983, 0)
RayGun.Size = UDim2.new(0, 121, 0, 49)
RayGun.Font = Enum.Font.GothamBold
RayGun.Text = "Ray Gun"
RayGun.TextColor3 = Color3.fromRGB(255, 219, 0)
RayGun.TextScaled = true
RayGun.TextSize = 14.000
RayGun.TextStrokeColor3 = Color3.fromRGB(174, 38, 148)
RayGun.TextWrapped = true
NAMEOFBUTTONHERE.MouseButton1Down:connect(function()
local Remote = game.Workspace.__THINGS.__REMOTES['weaponequipped']
local Arguments = {
[1] = {
[1] = {
[1] = "Ray Gun"
},
[2] = {
[1] = false
}
}
}
Remote:FireServer(unpack(Arguments))
end)
UICorner_8.Parent = RayGun
SniperRifle.Name = "Sniper Rifle"
SniperRifle.Parent = ScreenGui
SniperRifle.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
SniperRifle.Position = UDim2.new(0.672924936, 0, 0.322972983, 0)
SniperRifle.Size = UDim2.new(0, 121, 0, 49)
SniperRifle.Font = Enum.Font.GothamBold
SniperRifle.Text = "Sniper Rifle"
SniperRifle.TextColor3 = Color3.fromRGB(255, 219, 0)
SniperRifle.TextScaled = true
SniperRifle.TextSize = 14.000
SniperRifle.TextStrokeColor3 = Color3.fromRGB(174, 38, 148)
SniperRifle.TextWrapped = true
NAMEOFBUTTONHERE.MouseButton1Down:connect(function()
local Remote = game.Workspace.__THINGS.__REMOTES['weaponequipped']
local Arguments = {
[1] = {
[1] = {
[1] = "Sniper Rifle"
},
[2] = {
[1] = false
}
}
}
Remote:FireServer(unpack(Arguments))
end)
UICorner_9.Parent = SniperRifle
With time you'll learn how to find such errors quickly. If you have no idea where to start, there are several ways to approach this.
read the code and in your mind check what is missing ( pro level )
delete everything from your code that is syntactically correct
in your example you'll end up with BlackHoleGun.MouseButton1Down:connect(function() which is an incomplete function call with an imcomplete function definition. So you know that you have to put an end at the end of that function's body and that you need to a ) to close that function call.
count things that come in pairs (most editors can do that).
in your example you have 36{, 36}, 54[, 54], 105(, 104) whoops! -> 1 ) short!
you have 8 ends for 0 do + 0 then + 9 function -> 1 end short!
now check where those things are missing and add them.
A very good way to avoid such errors is to have your text editor/ide autocomplete pairs.
You're missing the end of the function BlackHoleGun.MouseButton1Down:connect you are declaring in line 53. There is no closing bracket.
I think you are missing
end)
after line 67.

Tonemap Fuse for Fusion based on Timothy Lottes algorithm (Lua)

I'm trying to build a Fuse (Fusion studio plugin) based on the tone mapper by Timothy Lottes : http://32ipi028l5q82yhj72224m8j.wpengine.netdna-cdn.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf
presented in this algorithm: https://github.com/Opioid/tonemapper/blob/master/tonemapper.py#L14-L42
The Fuse is accepted by Fusion, but crashes when I'm trying to use it. Could anyone give me some feedback please at what I am doing wrong?
Thanks
(Fuses are written in Lua)
--[[
Tone Mapper based on
http://32ipi028l5q82yhj72224m8j.wpengine.netdna-cdn.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf
https://github.com/Opioid/tonemapper/blob/master/tonemapper.py#L14-L42
version 2021 01 05 by Pieter Dumoulin
]]--
FuRegisterClass("ToneMapper", CT_SourceTool, {
REGS_Category = "Fuses",
REGS_Name = "Tone Mapper",
REGS_OpIconString = "TM",
REGS_OpDescription = "Tone Mapper",
REG_OpNoMask = true
})
function Create()
InContrast = self:AddInput("Contrast", "Contrast", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 5,
INP_Default = 1.2,
})
InShoulder = self:AddInput("Shoulder", "Shoulder", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 5,
INP_Default = 0.97,
})
InMidIn = self:AddInput("Middle Grey In", "mid_in", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 1,
INP_Default = 0.4,
})
InMidOut = self:AddInput("Middle Grey Out", "mid_out", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 1,
INP_Default = 0.18,
})
InHdrMax = self:AddInput("HdrMax", "Hdr_Max", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 100,
INP_Default = 64,
})
InImage = self:AddInput("Input", "Input", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
OutImage = self:AddOutput("Output", "Output", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
end
function maxrgbfunc()
if p.R == p.G == p.B then return p.G
elseif p.G == math.max(p.R, p.B) then return p.G
elseif p.B == math.max(p.G, p.R) then return p.B
elseif p.R == math.max(p.G, p.B) then return p.R
else return math.max(p.R, math.max(p.G, p.B))
end
function tonemapfunc()
local peak = math.min(maxRGB, self_hdr_max)
local curve = (peak ^ self_a) / (((peak ^ self_a) ^ self_d) * self_b + self_c)
return curve
end
function Process(req)
local img = InImage:GetValue(req)
local a = InContrast:GetValue(req).Value
local d = InShoulder:GetValue(req).Value
local mid_in = InMidIn:GetValue(req).Value
local mid_out = InMidOut:GetValue(req).Value
local hdr_max = InHdrMax:GetValue(req).Value
local ad = a * d
local midi_pow_a = mid_in ^ a
local midi_pow_ad = mid_in ^ ad
local hdrm_pow_a = hdr_max ^ a
local hdrm_pow_ad = hdr_max ^ ad
local u = hdrm_pow_ad * mid_out - midi_pow_ad * mid_out
local v = midi_pow_ad * mid_out
local self_a = a
local self_d = d
local self_b = -((-midi_pow_a + (mid_out * (hdrm_pow_ad * midi_pow_a - hdrm_pow_a * v)) / u) / v)
local self_c = (hdrm_pow_ad * midi_pow_a - hdrm_pow_a * v) / u
local self_hdr_max = hdr_max
local out = Image({IMG_Like = img})
self:DoMultiProcess(nil, { In = img, Out = out, MaxRGB = maxrgb }, img.Height, function (y)
local p = Pixel()
for x=0,In.Width-1 do
In:GetPixel(x,y, p)
maxRGB = maxrgbfunc(x, y, p)
local peak = tonemapfunc(maxRGB, self_hdr_max, self_a, self_d, self_b, self_c, x, y, p)
local ratioR = p.R / maxRGB
local ratioG = p.G / maxRGB
local ratioB = p.B / maxRGB
p.R = peak * ratioR
p.G = peak * ratioG
p.B = peak * ratioB
Out:SetPixel(x,y, p)
end
end)
end
OutImage:Set(req,out)
end

Why does unequipping this tool relocates the player to the center of the map in Roblox?

This gear was inserted from the Catalog. It relocates the player to the center of the map when it's unequipped by clicking on the thumbnail. At 1st, I tested in a game I made. Everytime I unequipped it, the player kept falling through the baseplate and dying. I noticed it is the same position over and over. I moved the baseplate's position lower and the player falls down onto the baseplate instead of dying. Then I tested the gear in a new empty baseplate, unequipping it, the player moves to the center, too. I check the position of the both the Handle and the player's Torso, but that axis does not match any position in the script. Can someone point this out for me so that I can change it to the last position that the player stops?
Tool = script.Parent
Handle = Tool:WaitForChild("Handle")
Players = game:GetService("Players")
Debris = game:GetService("Debris")
Assets = require(Tool:WaitForChild("Assets"))
Data = Assets.Data
BaseUrl = Assets.BaseUrl
BasePart = Instance.new("Part")
BasePart.Material = Enum.Material.Plastic
BasePart.Shape = Enum.PartType.Block
BasePart.TopSurface = Enum.SurfaceType.Smooth
BasePart.BottomSurface = Enum.SurfaceType.Smooth
BasePart.FormFactor = Enum.FormFactor.Custom
BasePart.Size = Vector3.new(0.2, 0.2, 0.2)
BasePart.Anchored = false
BasePart.CanCollide = true
BasePart.Locked = true
Animations = {
Hold = {Animation = Tool:WaitForChild("Hold"), FadeTime = nil, Weight = nil, Speed = nil}
}
Sounds = {
Honk = Handle:WaitForChild("Honk"),
Engine = Handle:WaitForChild("Running")
}
Controls = {
Forward = {Key = "w", ByteKey = 17, Mode = false},
Backward = {Key = "s", ByteKey = 18, Mode = false},
Left = {Key = "a", ByteKey = 20, Mode = false},
Right = {Key = "d", ByteKey = 19, Mode = false}
}
Rate = (1 / 60)
Gravity = 196.20
PoseOffset = CFrame.new(0, -1.5125, -0.3) * CFrame.Angles(0, 0, 0) --The offset your character is from the center of the vehicle.
SpeedBoost = {
Allowed = false,
Active = false,
Enabled = true,
Duration = 10,
ReloadTime = 30
}
Special = {
Allowed = false,
Enabled = true,
Active = false,
Duration = 0,
ReloadTime = 60
}
Speed = {
Acceleration = {
Normal = 30,
Boost = 30
},
Deceleration = {
Normal = 30,
Boost = 30
},
MovementSpeed = {
Normal = {Min = 20, Max = 70},
Boost = {Min = 20, Max = 70}
},
TurnSpeed = {
Speed = {Min = 5, Max = 5},
TurnAlpha = 0.30,
AlphaDampening = 0.2
},
}
MaxSpeed = { --Maximum speed which the vehicle can move and turn at.
Movement = Speed.MovementSpeed.Normal,
Turn = Speed.TurnSpeed.Speed,
Acceleration = Speed.Acceleration.Normal,
Deceleration = Speed.Deceleration.Normal
}
CurrentSpeed = { --The speed which the vehicle is moving and turning at.
Movement = 0,
Turn = 0
}
Honk = {
Honking = false,
LastHonk = 0,
ReloadTime = 1
}
Jump = {
Jumping = false,
LastJump = 0,
ReloadTime = 1.25,
JumpForce = 30
}
ToolEquipped = false
ServerControl = (Tool:FindFirstChild("ServerControl") or Instance.new("RemoteFunction"))
ServerControl.Name = "ServerControl"
ServerControl.Parent = Tool
ClientControl = (Tool:FindFirstChild("ClientControl") or Instance.new("RemoteFunction"))
ClientControl.Name = "ClientControl"
ClientControl.Parent = Tool
Tool.Enabled = true
function RayCast(Position, Direction, MaxDistance, IgnoreList)
local IgnoreList = ((type(IgnoreList) == "table" and IgnoreList) or {IgnoreList})
return game:GetService("Workspace"):FindPartOnRayWithIgnoreList(Ray.new(Position, Direction.unit * (MaxDistance or 999.999)), IgnoreList)
end
function GetAllConnectedParts(Object)
local Parts = {}
local function GetConnectedParts(Object)
for i, v in pairs(Object:GetConnectedParts()) do
local Ignore = false
for ii, vv in pairs(Parts) do
if v == vv then
Ignore = true
end
end
if not Ignore then
table.insert(Parts, v)
GetConnectedParts(v)
end
end
end
GetConnectedParts(Object)
return Parts
end
function EnableFirstPersonView()
if not CheckIfAlive() or not ToolEquipped then
return
end
local Limbs = {"LeftHand", "RightHand"}
for i, v in pairs(Limbs) do
local Limb = Character:FindFirstChild(v)
if Limb:IsA("BasePart") then
Spawn(function()
InvokeClient("SetLocalTransparencyModifier", {Object = Limb, Transparency = 0, AutoUpdate = false})
end)
end
end
end
function ThrustUpdater()
for i, v in pairs(CurrentSpeed) do
CurrentSpeed[i] = 0
end
for i, v in pairs(Controls) do
Controls[i].Mode = false
end
while ToolEquipped and Body and Body.Parent and CheckIfAlive() and RotationForce and RotationForce.Parent and ThrustForce and ThrustForce.Parent and TurnGyro and TurnGyro.Parent do
RotationForce.angularvelocity = Vector3.new(0, CurrentSpeed.Turn, 0)
if math.abs(CurrentSpeed.Turn) > Speed.TurnSpeed.AlphaDampening then
CurrentSpeed.Turn = (CurrentSpeed.Turn - (Speed.TurnSpeed.AlphaDampening * (math.abs(CurrentSpeed.Turn) / CurrentSpeed.Turn)))
else
CurrentSpeed.Turn = 0
end
if not Controls.Forward.Mode or Controls.Backward.Mode then --Slow down if not controlling.
CurrentSpeed.Movement = (CurrentSpeed.Movement * 0.99)
end
local MySpeed = Vector3.new(Body.Velocity.X, 0, Body.Velocity.Z).magnitude
local VelocityDifference = math.abs((MySpeed - (ThrustForce.velocity.magnitude)))
if MySpeed > 3 and ThrustForce.velocity.magnitude > 3 and VelocityDifference > (0.7 * ThrustForce.velocity.magnitude) then
CurrentSpeed.Movement = (CurrentSpeed.Movement * 0.9)
end
if Controls.Forward.Mode then --Handle acceleration
CurrentSpeed.Movement = math.min(MaxSpeed.Movement.Max, (CurrentSpeed.Movement + (MaxSpeed.Acceleration * Rate)))
end
if Controls.Backward.Mode then --Handle deceleration, if speed is more than 0, decrease quicker.
CurrentSpeed.Movement = math.max(-MaxSpeed.Movement.Min, (CurrentSpeed.Movement - (MaxSpeed.Deceleration * ((CurrentSpeed.Movement > 0 and 2.8) or 1) * Rate)))
end
if Controls.Left.Mode then --Handle left turn speed
CurrentSpeed.Turn = math.min(Speed.TurnSpeed.Speed.Max, (CurrentSpeed.Turn + (Speed.TurnSpeed.TurnAlpha)))
end
if Controls.Right.Mode then --Handle right turn speed
CurrentSpeed.Turn = math.max(-Speed.TurnSpeed.Speed.Min, (CurrentSpeed.Turn - (Speed.TurnSpeed.TurnAlpha)))
end
local Direction = UpperTorso.CFrame.lookVector
Direction = Vector3.new(Direction.x, 0, Direction.z).unit
local Velocity = (Direction * CurrentSpeed.Movement) --The thrust force which you move.
ThrustForce.velocity = Vector3.new(Velocity.X, ThrustForce.velocity.Y, Velocity.Z)
local LeanAmount = (-CurrentSpeed.Turn * (math.pi / 6) / 4) --Amount your character leans over.
local XZAngle = math.atan2(UpperTorso.CFrame.lookVector.z, 0, UpperTorso.CFrame.lookVector.x) --Handle rotation
TurnGyro.cframe = CFrame.Angles((LeanAmount * Direction.x), 0, (LeanAmount * Direction.z))
--Wheel animation
local DesiredAngle = (999999999 * (-CurrentSpeed.Movement / math.abs(CurrentSpeed.Movement)))
local MaxVelocity = (CurrentSpeed.Movement / 250)
for i, v in pairs({FrontMotor, BackMotor}) do
if v and v.Parent then
v.DesiredAngle = DesiredAngle
v.MaxVelocity = MaxVelocity
end
end
--Smoke exhaust from vehicle running.
for i, v in pairs(ExhaustSmoke) do
if v and v.Parent then
v.Opacity = ((math.min(math.abs(CurrentSpeed.Movement), 10) / 10) * 0.5)
end
end
--Engine running sound which pitch changes while in motion.
Sounds.Engine.Pitch = (1 + (math.abs(CurrentSpeed.Movement / MaxSpeed.Movement.Max) * 1))
wait(Rate)
end
end
function SpawnVehicle()
Handle.Transparency = 1
Spawn(function()
InvokeClient("PlaySound", Sounds.Engine)
InvokeClient("PlayAnimation", Animations.Hold)
end)
Humanoid.PlatformStand = true
local VehicleData = Assets.CreateVehicle()
Body = VehicleData.Vehicle
local ParticleTable = VehicleData.Tables
--FrontMotor = Body.FrontMotor
--BackMotor = Body.BackMotor
ExhaustSmoke = ParticleTable.ExhaustSmoke
Lights = ParticleTable.Lights
Sparkles = ParticleTable.Sparkles
if SpeedBoost.Active then
for i, v in pairs(Sparkles) do
if v and v.Parent then
v.Enabled = true
end
end
end
local UpperTorsoWeld = Instance.new("Weld")
UpperTorsoWeld.C0 = PoseOffset
UpperTorsoWeld.Part0 = UpperTorso
UpperTorsoWeld.Part1 = Body
UpperTorsoWeld.Parent = Body
Body.CanCollide = true
RotationForce = Instance.new("BodyAngularVelocity")
RotationForce.maxTorque = Vector3.new(0, math.huge, 0)
RotationForce.angularvelocity = Vector3.new(0, 0, 0)
RotationForce.Parent = UpperTorso
ThrustForce = Instance.new("BodyVelocity")
ThrustForce.maxForce = Vector3.new(math.huge, 0, math.huge)
ThrustForce.velocity = Vector3.new(0, 0, 0)
ThrustForce.P = 100
ThrustForce.Parent = UpperTorso
TurnGyro = Instance.new("BodyGyro")
TurnGyro.maxTorque = Vector3.new(5000, 0, 5000)
TurnGyro.P = 300
TurnGyro.D = 100
TurnGyro.Parent = UpperTorso
Body.Parent = Tool
local RayHit, RayPos, RayNormal = RayCast(UpperTorso.Position, Vector3.new(0, -1, 0), (UpperTorso.Size.Y * 2), {Character})
if RayHit then
UpperTorso.CFrame = UpperTorso.CFrame + Vector3.new(0, ((Character:GetModelSize().Y / 2) + 1.5), 0)
end
Spawn(ThrustUpdater)
end
function FreezePlayer()
if CheckIfAlive() then
local FreezePart = BasePart:Clone()
FreezePart.Name = "FreezePart"
FreezePart.Transparency = 1
FreezePart.Anchored = true
FreezePart.CanCollide = false
local FreezeWeld = Instance.new("Weld")
FreezeWeld.Part0 = UpperTorso
FreezeWeld.Part1 = FreezePart
FreezeWeld.Parent = FreezePart
Debris:AddItem(FreezePart, 0.125)
FreezePart.Parent = Character
UpperTorso.Velocity = Vector3.new(0, -25, 0)
UpperTorso.RotVelocity = Vector3.new(0, 0, 0)
end
end
function CleanUp()
Handle.Velocity = Vector3.new(0, 0, 0)
Handle.RotVelocity = Vector3.new(0, 0, 0)
for i, v in pairs({}) do
if v then
v:disconnect()
end
end
for i, v in pairs({Body, RotationForce, ThrustForce, TurnGyro}) do
if v and v.Parent then
v:Destroy()
end
end
for i, v in pairs(Tool:GetChildren()) do
if v:IsA("BasePart") and v ~= Handle then
v:Destroy()
end
end
end
function CheckIfAlive()
return (((Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and UpperTorso and UpperTorso.Parent and Player and Player.Parent) and true) or false)
end
function Equipped(Mouse)
Character = Tool.Parent
Player = Players:GetPlayerFromCharacter(Character)
Humanoid = Character:FindFirstChild("Humanoid")
UpperTorso = Character:FindFirstChild("UpperTorso")
if not CheckIfAlive() then
return
end
Spawn(CleanUp)
Spawn(EnableFirstPersonView)
Spawn(SpawnVehicle)
ToolEquipped = true
end
function Unequipped()
Spawn(CleanUp)
Spawn(FreezePlayer)
for i, v in pairs(Sounds) do
v:Stop()
Spawn(function()
InvokeClient("StopSound", v)
end)
end
if CheckIfAlive() then
Humanoid.PlatformStand = false
end
Handle.Transparency = 0
ToolEquipped = false
end
function OnServerInvoke(player, mode, value)
if player == Player and ToolEquipped and value and CheckIfAlive() then
if mode == "KeyPress" then
local Down = value.Down
local Key = value.Key
local ByteKey = string.byte(Key)
for i, v in pairs(Controls) do
if Key == v.Key or ByteKey == v.ByteKey then
Controls[i].Mode = Down
end
end
if Key == " " and Down then --Jump controller
if math.abs(tick() - Jump.LastJump) > Jump.ReloadTime and not Jump.Jumping and ThrustForce and ThrustForce.Parent then
Jump.Jumping = true
local Parts = GetAllConnectedParts(Body)
local Mass = 0
for i, v in pairs(Parts) do
Mass = (Mass + v:GetMass())
end
ThrustForce.maxForce = Vector3.new(ThrustForce.maxForce.X, ((Mass * Gravity) * 100), ThrustForce.maxForce.Z)
ThrustForce.velocity = (Vector3.new(0, 1, 0) * Jump.JumpForce) + Vector3.new(ThrustForce.velocity.X, 0, ThrustForce.velocity.Z)
wait(0.1)
ThrustForce.maxForce = Vector3.new(ThrustForce.maxForce.X, 0, ThrustForce.maxForce.Z)
ThrustForce.velocity = Vector3.new(ThrustForce.velocity.X, 0, ThrustForce.velocity.Z)
Jump.LastJump = tick()
Jump.Jumping = false
end
elseif Key == "x" and Down then --Toggle light(s) on/off.
for i, v in pairs(Lights) do
if v and v.Parent then
v.Enabled = not v.Enabled
end
end
elseif Key == "h" and Down then --Play honk sound.
local Sound = Sounds.Honk
if (tick() - Honk.LastHonk) >= (Sound.TimeLength + Honk.ReloadTime) and not Honk.Honking then
Honk.Honking = true
local TempSound = Sound:Clone()
Debris:AddItem(TempSound, Sound.TimeLength)
TempSound.Parent = Body
TempSound:Play()
Honk.LastHonk = tick()
Honk.Honking = false
end
elseif Key == "q" and Down then --Activate special.
if not Special.Allowed or not Special.Enabled or Special.Active then
return
end
Special.Enabled = false
Special.Active = true
wait(Special.Duration)
Special.Active = false
wait(Special.ReloadTime)
Special.Enabled = true
elseif ByteKey == 48 and Down then --Activate speed boost.
if not SpeedBoost.Allowed or not SpeedBoost.Enabled or SpeedBoost.Active then
return
end
SpeedBoost.Enabled = false
SpeedBoost.Active = true
for i, v in pairs(Sparkles) do
if v and v.Parent then
v.Enabled = true
end
end
MaxSpeed.Acceleration = Speed.Acceleration.Boost
MaxSpeed.Deceleration = Speed.Deceleration.Boost
MaxSpeed.Movement = Speed.MovementSpeed.Boost
wait(SpeedBoost.Duration)
MaxSpeed.Acceleration = Speed.Acceleration.Normal
MaxSpeed.Deceleration = Speed.Deceleration.Normal
MaxSpeed.Movement = Speed.MovementSpeed.Normal
for i, v in pairs(Sparkles) do
if v and v.Parent then
v.Enabled = false
end
end
SpeedBoost.Active = false
wait(SpeedBoost.ReloadTime)
SpeedBoost.Enabled = true
end
end
end
end
function InvokeClient(Mode, Value)
local ClientReturn = nil
pcall(function()
ClientReturn = ClientControl:InvokeClient(Player, Mode, Value)
end)
return ClientReturn
end
Spawn(CleanUp)
ServerControl.OnServerInvoke = OnServerInvoke
Tool.Equipped:connect(Equipped)
Tool.Unequipped:connect(Unequipped)
I found it. Freezingplayer is the culprit. I took out "Spawn(FreezePlayer)" when it is unequipped and it works.
function Unequipped()
Spawn(CleanUp)
---Spawn(FreezePlayer)

Resources