.lua error 'then' expected near 'else' - lua

I am having this error, can't find the error.
local choice_revive = {function(player,choice)
local user_id = vRP.getUserId(player)
if user_id ~= nil then
vRPclient.getNearestPlayer(player,{10},function(nplayer)
local nuser_id = vRP.getUserId(nplayer)
if nuser_id ~= nil then
vRPclient.isInComa(nplayer,{}, function(in_coma)
if in_coma then
if vRP.tryGetInventoryItem(user_id,"medkit",1,true) else
vRP.tryGetInventoryItem(user_id,"smartwatch",1,true)
io.write("Smartwatch: Tilkalder Ambulance")
then
vRPclient.playAnim(player,{false,revive_seq,false}) -- anim
SetTimeout(15000, function()
vRPclient.varyHealth(nplayer,{50}) -- heal 50
end)
end
else
vRPclient.notify(player,{lang.emergency.menu.revive.not_in_coma()})
end
end)
else
vRPclient.notify(player,{lang.common.no_player_near()})
end
end)
end
end,lang.emergency.menu.revive.description()}
I have tried to make, and look for error, but without luck.
- If anyone can fix it, tell me please.

if statement, functions and for statement must be ended with end.
this code must be like that
--Settings--
local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")
vRP = Proxy.getInterface("vRP")
vRPclient = Tunnel.getInterface("vRP","vRP_smartwatch")
if in_coma then
vRP.tryGetInventoryItem(user_id,"smartwatch",1,true)
io.write("Smartwatch: Tilkalder Ambulance")
end
function vRP.sendServiceAlert(sender, emergency,x,y,z, msg)
local service = services[service_name]
local answered = false
if service then
local players = {}
for k,v in pairs(vRP.rusers) do
local player = vRP.getUserSource(tonumber(k))
-- check user
if vRP.hasPermission(k,service.alert_permission) and player ~= nil then
table.insert(players,player)
end
end
end
end

Related

Attempt to index nil with FindFirstChild

Script:
local ToolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedItems")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(player)
local ToolData = SaveData:GetAsync(player.UserId)
local BackPack = player:WaitForChild("Backpack")
local StarterGear = player:WaitForChild("StarterGear")
if ToolData ~= nil then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) and BackPack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
ToolFolder[v]:Clone().Parent = BackPack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local ToolTable = {}
for i,v in pairs(player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil then
SaveData:SetAsync(player.UserId, ToolTable)
end
end)
Issue:
ServerScriptService.SaveTools:12: attempt to index nil with 'FindFirstChild'
Couldn't find a solution. Appreciate any help. :)
Any time you see "attempt to index nil with x" you need to look at where you are asking for "x" and realize that the object holding "x" doesn't exist. The job then becomes figuring out why that object doesn't exist.
In your case, whatever object that you are calling "FindFirstChild" on line 12 doesn't exist. Sadly, line 12 uses this three times :
if ToolFolder:FindFirstChild(v) and
BackPack:FindFirstChild(v) == nil and
StarterGear:FindFirstChild(v) == nil then
So let's look at where ToolFolder, BackPack, and StarterGear were created and see if that gives any clues.
local ToolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedItems")
...
local BackPack = player:WaitForChild("Backpack")
local StarterGear = player:WaitForChild("StarterGear")
Backpack and StarterGear looks correct, they are both children of the Player, and both look to be spelled correctly.
ToolFolder is probably the culprit, you should make sure there is actually an object named SavedItems in ServerStorage. Double check that the spelling and capitalization are correct.

How to make a base system? -- Roblox Lua

I'm trying to make a system to which when the player joins they are given a base and then no other players can use that base.
Here is my module inside the parented to the script:
local Functions = {}
function Functions.findOpenBase(plr)
local bases = workspace.Bases
for i,v in pairs(bases:GetChildren()) do
if v:IsA("Part") then
print("Searching..")
if plr.alreadyOwnsBase.Value == false then
if v.Owner.Value ~= nil then
print("Base found!")
v.Owner.Value = plr.Name
plr.alreadyOwnsBase.Value = true
else
warn("error")
plr:Kick("error finding base, Please Rejoin.")
end
end
else
print("cannot claim another base")
end
end
end
return Functions
then here is my handler script:
local module = require(script.Functions)
game.Players.PlayerAdded:Connect(function(plr)
local alreadyOwnsBase = Instance.new("BoolValue", plr)
alreadyOwnsBase.Name = "alreadyOwnsBase"
alreadyOwnsBase.Value = false
if plr then
module.findOpenBase(plr)
print(plr.Name)
end
end)
is there any solutions?
To me, module inside the parented to the script:
local Functions = {}
function Functions.findOpenBase(plr)
-- check it first.
if plr.alreadyOwnsBase.Value == false then
local bases = workspace.Bases
for i,v in pairs(bases:GetChildren()) do
print("Searching..")
if v:IsA("Part") then
if v.Owner.Value ~= nil then
print("Base found!")
v.Owner.Value = plr.Name
plr.alreadyOwnsBase.Value = true
-- get it, jump the loop
break
end
else
print("cannot claim another base")
end
end
end
-- and plr.alreadyOwnsBase.Value is the flag of the result
if plr.alreadyOwnsBase.Value == false then
warn("error")
plr:Kick("error finding base, Please Rejoin.")
end
end
return Functions
and the handler script:
local module = require(script.Functions)
game.Players.PlayerAdded:Connect(function(plr)
local alreadyOwnsBase = Instance.new("BoolValue", plr)
alreadyOwnsBase.Name = "alreadyOwnsBase"
alreadyOwnsBase.Value = false
if plr then
module.findOpenBase(plr)
-- check the flag
if plr.alreadyOwnsBase.Value then
print(plr.Name)
end
end
end)

Inf timestop glitch in roblox studio ( ServerScriptService.TheWorldServer.TS:35: attempt to index nil with 'Name')

I keep getting this error The error is only for this code. It causes the timestop to be infinite Does anyone know how to fix it? The error is ServerScriptService.TheWorldServer.TS:35: attempt to index
nil with 'Name' Any help is very appreciated.
I have no idea how to fix this so I help is VERY helpful.
local music = game.Workspace.BackgroundMusic
local model = game.ReplicatedStorage.Stand
local InUse = game.ReplicatedStorage.InUse
local bacon = {}
local G = {}
model.BaconTimeStop.OnServerEvent:Connect(function(player)
local find = workspace:GetDescendants()
if InUse.Value == false then
InUse.Value = true
local Sound = script.TSSound:Clone()
Sound.Parent = workspace
Sound:Play()
music:Pause()
wait(1.8)
local TweenService = game:GetService("TweenService")
local part = game.Lighting.ColorCorrection
local goal = {}
goal.Contrast = -2
local tweenInfo = TweenInfo.new(0.2)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
for i=1, #find do
local That = find[i]
if That:IsA("Part") or That:IsA("MeshPart") then
if That.Anchored == false and That.Parent.Name ~= player.Name and That.Parent.Parent.Name ~= player.Name and That.Name ~= "Baseplate" and not That.Parent:IsA("Accessory") then
That.Anchored = true
table.insert(bacon, That)
end
end
if That:IsA("ParticleEmitter") then
That.TimeScale = 0
table.insert(G, That)
end
end
wait(3)
InUse.Value = false
local TweenService = game:GetService("TweenService")
local part = game.Lighting.ColorCorrection
local goal = {}
goal.Contrast = 0
local tweenInfo = TweenInfo.new(0.2)
local tween = TweenService:Create(part, tweenInfo, goal)
music:Resume()
tween:Play()
for i=1, #bacon do
bacon[i].Anchored = false
end
table.clear(bacon)
for i=1, #G do
G[i].TimeScale = 1
end
table.clear(G)
end
end)
The error message tells you everything you need to know.
ServerScriptService.TheWorldServer.TS:35: attempt to index nil with
'Name'
This is line 35:
if That.Anchored == false
and That.Parent.Name ~= player.Name
and That.Parent.Parent.Name ~= player.Name
and That.Name ~= "Baseplate"
and not That.Parent:IsA("Accessory") then
You index multiple variables with Name as in .Name (indexing operator .).
One of these values is nil.
That cannot be nil as this would cause errors earlier.
print player, That.Parent, and That.Parent.Parent to find out which of them is nil. Then find out why and fix that. We cannot help you here. If it is a valid state simply avoid indexing or replace it by some default value.

Roblox Studio error: Workspace.Driver.OnSeated!:13: attempt to index nil with ''Name''

I am having an error with one of my scripts in Roblox Studio. The line that shows that is a problem is Line 13. The script is for basically to weld when somebody sits on the seat, and to start up the TankGUI (Another script that is fine).
seat = script.Parent
function onChildAdded(part)
if (part.className == "Weld") then
while true do
local welde = seat:FindFirstChild("SeatWeld")
if (welde ~= nil) then
local sitted = welde.Part1.Parent
end
if (sitted.Name ~= script.Parent.Owner.Value) then
if (script.Parent.Owner.Value == "NoOne") then
script.Parent.Owner.Value = sitted.Name
print ("sitted steal")
else
print ("stolen!!")
local shipstealer = game.Workspace:FindFirstChild(sitted.Name)
if (shipstealer ~= nil) then
shipstealer.Humanoid.Jump=true
end
end
end
wait(0.2)
if (welde == nil) then
print("BreakLoop")
script.Parent.Owner.Value = "NoOne"
break end
end
end
end
--while true do
-- wait(0.5)
-- script.Parent.Parent.Name=script.Parent.Owner.Value .. "'s Ship"
--end
seat.ChildAdded:connect(onChildAdded)
Please excuse any poor co-operation or language barriers I'm having. I'm still a bit new here.
if (welde ~= nil) then
local sitted = welde.Part1.Parent
end
if (sitted.Name ~= script.Parent.Owner.Value) then
Since you're declaring sitted as local, it goes out of scope at end, so it's gone when you try to use it in that if, so you're actually using a nil global variable there. Do this instead:
local sitted
if (welde ~= nil) then
sitted = welde.Part1.Parent
end
if (sitted.Name ~= script.Parent.Owner.Value) then
That way it'll stay in scope until you're actually done with it.

Cloning+Dragging model when button is click ROBLOX [LUA]?

So I thought of having this for so long, I just don't know where to start. I am new to this language and I keep learning, but kind of hard for me. But I have built my very own custom character which took 2 weeks for me. Anyway, For my question. An example is if I have a button and I click it, a model will be clone and I can drag that model and put it anywhere nearby. What possible method I can use to achieve this?
First things first, I suggest for any future questions, you head over to https://scriptinghelpers.org/
now, on to your question, for cloning the model, you should use mouse.Target.Parent:Clone() or the GetTopParent(mouse.Target) function in my function library (which you can get here; http://www.roblox.com/item.aspx?id=244244638)
then deposit the model into workspace and MakeJoints()
the next step is to move the model, this can be tricky, but the simplest method is model:MoveTo(mouse.Hit.p) on mouse.Moved (but that's a little buggy)
Another method for movement would be to use the Handles class, but I'm not really familiar with it, so you'd have to figure that one out on your own.
To make the first method less buggy, I'd suggest something along the lines of
model:MoveTo(mouse.Hit.p.X, mouse.Target.Position.Y + (model:GetExtentsSize().Y / 2), mouse.Hit.p.Z)
but you'd have to set up the mouse to ignore the model, which I can't really help with.
A really good place to start is to search the free models in Studio Toolbox for a 'Dragger Tool' or 'Model Dragger Tool' and then use the script inside to get started creating your own. I have learned to create my own custom draggers by doing this and it is way easier than you may think at first. Once you find a good dragger tool to borrow code from, if you need to enhance it, you can find the dragger api in the Roblox Wiki to help you further customize it to your specific needs.
http://wiki.roblox.com/index.php?title=API:Class/Dragger
EDIT: So here's the first dragger script that showed when I searched. It will drag models and parts but you will have to edit it to meet your requirements using the dragger api. Create a Tool in player.BackPack then create a LocalScript inside the Tool then copy and paste the code below into the LocalScript, and that will get you started.
local Tool = script.Parent
enabled = true
local origTexture = Tool.TextureId
game:GetService("ContentProvider"):Preload("rbxasset://icons/freemove_sel.png")
local selectionBox
local currentSelection
local currentSelectionColors = {}
local selectionLasso
local inGui = false
local inPalette = false
local lockTime = 0
function canSelectObject(part)
return part and not (part.Locked) and (part.Position - script.Parent.Parent.Head.Position).Magnitude < 60
end
function findModel(part)
while part ~= nil do
if part.className == "Model" then
return part
end
part = part.Parent
end
return nil
end
function startDrag(mousePart, hitPoint, collection)
dragger = Instance.new("Dragger")
pcall(function() dragger:MouseDown(mousePart, hitPoint, collection) end)
end
function collectBaseParts(object, collection)
if object:IsA("BasePart") then
collection[#collection+1] = object
end
for index,child in pairs(object:GetChildren()) do
collectBaseParts(child, collection)
end
end
function onMouseDown(mouse)
mouse.Icon ="rbxasset://textures\\GrabRotateCursor.png"
local part = mouse.Target
if canSelectObject(part) then
local hitPoint = mouse.Hit:toObjectSpace(part.CFrame).p
if trySelection(part) then
local instances = {}
collectBaseParts(currentSelection, instances)
startDrag(part, hitPoint, instances)
return
end
end
--Clear the selection if we weren't able to lock succesfullu
onMouseUp(mouse)
end
function onMouseUp(mouse)
mouse.Icon ="rbxasset://textures\\GrabCursor.png"
if dragger ~= nil then
pcall(function() dragger:MouseUp() end)
dragger = nil
end
end
function trySelection(part)
if canSelectObject(part) then
selectionLasso.Part = part
local model = findModel(part)
if model then
return setSelection(model)
else
return setSelection(part)
end
else
clearSelection()
return false
end
end
function onKeyDown(key)
if dragger ~= nil then
if key == 'R' or key == 'r' then
dragger:AxisRotate(Enum.Axis.Y)
elseif key == 'T' or key == 't' then
dragger:AxisRotate(Enum.Axis.Z)
end
end
end
local alreadyMoving
function onMouseMove(mouse)
if alreadyMoving then
return
end
alreadyMoving = true
if dragger ~= nil then
--Maintain the lock
if time() - lockTime > 3 then
Instance.Lock(currentSelection)
lockTime = time()
end
--Then drag
pcall(function() dragger:MouseMove(mouse.UnitRay) end)
else
trySelection(mouse.Target)
end
alreadyMoving = false
end
function saveSelectionColor(instance)
if instance:IsA("BasePart") then
currentSelectionColors[instance] = instance.BrickColor
if instance.BrickColor == BrickColor.Blue() then
instance.BrickColor = BrickColor.new("Deep blue")
else
instance.BrickColor = BrickColor.Blue()
end
end
local children = instance:GetChildren()
if children then
for pos, child in pairs(children) do
saveSelectionColor(child)
end
end
end
function setSelection(partOrModel)
if partOrModel ~= currentSelection then
clearSelection()
if Instance.Lock(partOrModel) then
lockTime = time()
currentSelection = partOrModel
saveSelectionColor(currentSelection)
selectionBox.Adornee = currentSelection
return true
end
else
if currentSelection ~= nil then
if time() - lockTime > 2 then
--Maintain the lock
if not(Instance.Lock(currentSelection)) then
--we lost the lock
clearSelection()
return false
else
lockTime = time()
return true
end
else
return true
end
end
end
return false
end
function clearSelection()
if currentSelection ~= nil then
for part, color in pairs(currentSelectionColors) do
part.BrickColor = color
end
selectionBox.Adornee = nil
Instance.Unlock(currentSelection)
end
currentSelectionColors = {}
currentSelection = nil
selectionLasso.Part = nil
selectionBox.Adornee = nil
end
function onEquippedLocal(mouse)
Tool.TextureId = "rbxasset://icons/freemove_sel.png"
local character = script.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(character)
inGui = false
inPalette = false
mouse.Icon ="rbxasset://textures\\GrabCursor.png"
mouse.Button1Down:connect(function() onMouseDown(mouse) end)
mouse.Button1Up:connect(function() onMouseUp(mouse) end)
mouse.Move:connect(function() onMouseMove(mouse) end)
mouse.KeyDown:connect(function(string) onKeyDown(string) end)
selectionBox = Instance.new("SelectionBox")
selectionBox.Name = "Model Delete Selection"
selectionBox.Color = BrickColor.Blue()
selectionBox.Adornee = nil
selectionBox.Parent = player.PlayerGui
selectionLasso = Instance.new("SelectionPartLasso")
selectionLasso.Name = "Model Drag Lasso"
selectionLasso.Humanoid = character.Humanoid
selectionLasso.archivable = false
selectionLasso.Visible = true
selectionLasso.Parent = game.workspace
selectionLasso.Color = BrickColor.Blue()
alreadyMoving = false
end
function onUnequippedLocal()
Tool.TextureId = origTexture
clearSelection()
selectionBox:Remove()
selectionLasso:Remove()
end
Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)

Resources