Access Form Events - What control to use to execute code dynamically - ms-access-2016

I have created a form to enter training events.
I have an unbound calculated control at the top of my form which reflects the status of the training. Calculated control source:
=IIf(IsNull([Txt_TrainComm]),"NEW",IIf(IsNull([Txt_TrainComp]),"COMMENCED",IIf(IsNull([txtAssNom]),"ASSESSMENT REQUIRED",IIf(IsNull([txtAssComp]),"ASSESSMENT - NOMINATED","ASSESSED"))))
My form has a few key dates (Text Box Names: txt_TrainComm, txt_TrainComp, txtAssNom & txtAssComp) to be entered in that order. What I want to happen is as the dates are entered other form controls are enabled, the footer is made visible etc. I have written a code that when placed in the Form Current Event works fine when switching from one record to the next. Please see my code so far below:
Private Sub Form_Current()
If Me.StatusName = "NEW" Then
Me.StatusName.Width = 1418
Me.Txt_TrainComp.Enabled = False
Me.Txt_TrainComm.Enabled = True
Me.Page_Assessment.Enabled = False
If Me.FormFooter.Visible = True Then
Me.FormFooter.Visible = False
Me.cmdShowdetails__.Caption = "Show Assessment <<"
Dim WindowHeightNEW As Long
WindowHeightNEW = Me.WindowHeight - Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightNEW
End If
End If
If Me.StatusName = "COMMENCED" Then
Me.StatusName.Width = 2552
Me.Txt_TrainComp.Enabled = True
Me.Txt_TrainComm.Enabled = True
Me.Page_Assessment.Enabled = False
If Me.FormFooter.Visible = True Then
Me.FormFooter.Visible = False
Me.cmdShowdetails__.Caption = "Show Assessment <<"
Dim WindowHeightCOMM As Long
WindowHeightCOMM = Me.WindowHeight - Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightCOMM
End If
End If
If Me.StatusName = "ASSESSMENT REQUIRED" Then
Me.StatusName.Width = 4253
Me.Txt_TrainComp.Enabled = True
Me.Txt_TrainComm.Enabled = True
Me.Page_Assessment.Enabled = True
If Me.FormFooter.Visible = False Then
Me.FormFooter.Visible = True
Me.cmdShowdetails__.Caption = "Hide Assessment <<"
Dim WindowHeightASSREQ As Long
WindowHeightASSREQ = Me.WindowHeight + Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightASSREQ
End If
End If'
If Me.StatusName = "ASSESSMENT - NOMINATED" Then
Me.StatusName.Width = 4925
Me.Txt_TrainComp.Enabled = False
Me.Txt_TrainComm.Enabled = False
Me.Page_Assessment.Enabled = True
If Me.FormFooter.Visible = False Then
Me.FormFooter.Visible = True
Me.cmdShowdetails__.Caption = "Hide Assessment <<"
Dim WindowHeightASSNOM As Long
WindowHeightASSNOM = Me.WindowHeight + Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightASSNOM
End If
End If
If Me.StatusName = "ASSESSED" Then
Me.StatusName.Width = 1985
Me.Txt_TrainComp.Enabled = False
Me.Txt_TrainComm.Enabled = False
Me.Page_Assessment.Enabled = True
If Me.FormFooter.Visible = False Then
Me.FormFooter.Visible = True
Me.cmdShowdetails__.Caption = "Hide Assessment <<"
Dim WindowHeightASSD As Long
WindowHeightASSD = Me.WindowHeight + Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightASSD
End If
End If
End Sub
What I cant get to work, is placing the code in the correct control event so that for example, when a date is entered into txt_TrainComp, the code is run dynamically. I have to switch to a different record and then back for the changes to take effect which isn't the desired result. I have tried BeforeUpdate, AfterUpdate, OnDirty, OnChange and they dont seem to work.
Is someone able to please have a look and make a suggestion to what event or code changes I need to make? Hopefully I have provided enough information.
Thank you in advance.

Thanks to RetiredGeek, FormObject_LostFocus() was the correct event to run the code after focus is changed.
Private Sub Txt_TrainComm_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub
Private Sub Txt_TrainComp_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub
Private Sub txtAssComp_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub
Private Sub txtAssNom_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub

Related

attempt to perform arithmetic (add) on string and number Error

when I touch the object, I want it to be deleted and come back after 2 seconds and add 1 coin. how can I do this?
local WheatAmount = script.Parent
local oyuncuParasi = "Coins"
duvar = false
function onTouch(vurus)
if duvar == false then
oyuncuParasi = oyuncuParasi +1;
duvar = true
vurus.Parent:Destroy()
WheatAmount.CanCollide = false
wait(2)
WheatAmount.CanCollide = true
duvar = false
end
end
script.Parent.Touched:connect(onTouch)
You are trying to add 1 to local oyuncuParasi = "Coins" which is currently a string...
Try this:
local WheatAmount = script.Parent
local oyuncuParasi = 0
duvar = false
function onTouch(vurus)
if duvar == false then
oyuncuParasi += 1; -- Adds a coin
duvar = true
WheatAmount.Transparent = 1 -- Set the object Transparent
WheatAmount.CanCollide = false
WheatAmount.CanTouch = false
wait(2)
WheatAmount.Transparent = 0 -- Set the object Not Transparent
WheatAmount.CanCollide = true
WheatAmount.CanTouch = true
duvar = false
end
end
script.Parent.Touched:connect(onTouch)
Note: Make sure you put this in a server sided script instead of local script in the Object.
Let me know if it worked and the results!!

FiveM client lua. Problem with shops point

I have a problem with dots, when you enter a clothing store or a barbershop, the menu opens and works well. But after that, anywhere on the map, when you press E, the menu of a clothing store or a barbershop opens.
Here is the code itself, I myself do not know what the problem is there.
QBCore = exports['qb-core']:GetCoreObject()
local LastZone = nil
local CurrentAction = nil
local CurrentActionMsg = ''
local hasAlreadyEnteredMarker = false
local allMyOutfits = {}
local isPurchaseSuccessful = false
local PlayerData = {}
-- Net Events
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
QBCore.Functions.TriggerCallback('fivem-appearance:getPlayerSkin', function(appearance)
exports['fivem-appearance']:setPlayerAppearance(appearance)
PlayerData = QBCore.Functions.GetPlayerData()
if Config.Debug then -- This will detect if the player model is set as "player_zero" aka michael. Will then set the character as a freemode ped based on gender.
Wait(5000)
if GetEntityModel(PlayerPedId()) == `player_zero` then
print('Player detected as "player_zero", Starting CreateFirstCharacter event')
TriggerEvent('qb-clothes:client:CreateFirstCharacter')
end
end
end)
end)
RegisterNetEvent('qb-clothes:client:CreateFirstCharacter', function() -- Event renamed so you dont need to change anything for this to work... hopefully....
QBCore.Functions.GetPlayerData(function(PlayerData)
local skin = 'mp_m_freemode_01'
if PlayerData.charinfo.gender == 1 then
skin = "mp_f_freemode_01"
end
exports['fivem-appearance']:setPlayerModel(skin)
local config = {
ped = false,
headBlend = true,
faceFeatures = true,
headOverlays = true,
components = true,
props = true,
}
exports['fivem-appearance']:setPlayerAppearance(appearance)
exports['fivem-appearance']:startPlayerCustomization(function(appearance)
if (appearance) then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
else
print('Canceled')
end
end, config)
end)
end, false)
AddEventHandler('fivem-appearance:hasExitedMarker', function(zone)
CurrentAction = nil
end)
RegisterNetEvent('fivem-appearance:clothingShop', function()
exports['qb-menu']:openMenu({
{
header = "👚 | Clothing Store Options",
isMenuHeader = true, -- Set to true to make a nonclickable title
},
{
header = "Buy Clothing - $"..Config.Money,
txt = "Pick from a wide range of items to wear",
params = {
event = "fivem-appearance:clothingMenu",
}
},
{
header = "Change Outfit",
txt = "Pick from any of your currently saved outfits",
params = {
event = "fivem-appearance:pickNewOutfit",
args = {
number = 1,
id = 2
}
}
},
{
header = "Save New Outfit",
txt = "Save a new outfit you can use later on",
params = {
event = "fivem-appearance:saveOutfit",
}
},
{
header = "Delete Outfit",
txt = "Yeah... We didnt like that one either",
params = {
event = "fivem-appearance:deleteOutfitMenu",
args = {
number = 1,
id = 2
}
}
},
})
end)
RegisterNetEvent('fivem-appearance:pickNewOutfit', function(data)
local id = data.id
local number = data.number
TriggerEvent('fivem-appearance:getOutfits')
Wait(150)
local outfitMenu = {
{
header = '< Go Back',
params = {
event = 'fivem-appearance:clothingShop'
}
}
}
for i=1, #allMyOutfits, 1 do
outfitMenu[#outfitMenu + 1] = {
header = allMyOutfits[i].name,
params = {
event = 'fivem-appearance:setOutfit',
args = {
-- number = (1 + i),
ped = allMyOutfits[i].pedModel,
components = allMyOutfits[i].pedComponents,
props = allMyOutfits[i].pedProps
}
}
}
end
exports['qb-menu']:openMenu(outfitMenu)
end)
RegisterNetEvent('fivem-appearance:getOutfits', function()
TriggerServerEvent('fivem-appearance:getOutfits')
end)
RegisterNetEvent('fivem-appearance:sendOutfits', function(myOutfits)
local Outfits = {}
for i=1, #myOutfits, 1 do
table.insert(Outfits, {id = myOutfits[i].id, name = myOutfits[i].name, pedModel = myOutfits[i].ped, pedComponents = myOutfits[i].components, pedProps = myOutfits[i].props})
end
allMyOutfits = Outfits
end)
RegisterNetEvent('fivem-appearance:setOutfit', function(data)
local pedModel = data.ped
local pedComponents = data.components
local pedProps = data.props
local playerPed = PlayerPedId()
local currentPedModel = exports['fivem-appearance']:getPedModel(playerPed)
if currentPedModel ~= pedModel then
exports['fivem-appearance']:setPlayerModel(pedModel)
Wait(500)
playerPed = PlayerPedId()
exports['fivem-appearance']:setPedComponents(playerPed, pedComponents)
exports['fivem-appearance']:setPedProps(playerPed, pedProps)
local appearance = exports['fivem-appearance']:getPedAppearance(playerPed)
TriggerServerEvent('fivem-appearance:save', appearance)
else
exports['fivem-appearance']:setPedComponents(playerPed, pedComponents)
exports['fivem-appearance']:setPedProps(playerPed, pedProps)
local appearance = exports['fivem-appearance']:getPedAppearance(playerPed)
TriggerServerEvent('fivem-appearance:save', appearance)
end
-- TriggerEvent('fivem-appearance:clothingShop')
end)
RegisterNetEvent('fivem-appearance:saveOutfit', function()
local keyboard = exports['qb-input']:ShowInput({
header = "Name your outfit",
submitText = "Create Outfit",
inputs = {
{
text = "Outfit Name",
name = "input",
type = "text",
isRequired = true
},
},
})
if keyboard ~= nil then
local playerPed = PlayerPedId()
local pedModel = exports['fivem-appearance']:getPedModel(playerPed)
local pedComponents = exports['fivem-appearance']:getPedComponents(playerPed)
local pedProps = exports['fivem-appearance']:getPedProps(playerPed)
Wait(500)
TriggerServerEvent('fivem-appearance:saveOutfit', keyboard.input, pedModel, pedComponents, pedProps)
QBCore.Functions.Notify('Outfit '..keyboard.input.. ' has been saved', 'success')
end
end)
RegisterNetEvent('fivem-appearance:deleteOutfitMenu', function(data)
local id = data.id
local number = data.number
TriggerEvent('fivem-appearance:getOutfits')
Wait(150)
local DeleteMenu = {
{
header = '< Go Back',
params = {
event = 'fivem-appearance:clothingShop'
}
}
}
for i=1, #allMyOutfits, 1 do
DeleteMenu[#DeleteMenu + 1] = {
header = 'Delete "'..allMyOutfits[i].name..'"',
txt = 'You will never be able to get this back!',
params = {
event = 'fivem-appearance:deleteOutfit',
args = allMyOutfits[i].id
}
}
end
exports['qb-menu']:openMenu(DeleteMenu)
end)
RegisterNetEvent('fivem-appearance:deleteOutfit', function(id)
TriggerServerEvent('fivem-appearance:deleteOutfit', id)
-- TriggerEvent('fivem-appearance:clothingShop')
QBCore.Functions.Notify('Outfit Deleted', 'error')
end)
RegisterNetEvent("fivem-appearance:purchase", function(bool)
isPurchaseSuccessful = bool
end)
RegisterNetEvent('fivem-appearance:clothingMenu', function()
TriggerServerEvent('fivem-appearances:buyclothing')
Wait(500)
if isPurchaseSuccessful then
local config = {
ped = false,
headBlend = false,
faceFeatures = false,
headOverlays = false,
components = true,
props = true
}
exports['fivem-appearance']:startPlayerCustomization(function(appearance)
if appearance then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
else
print('Canceled')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
end
end, config)
end
end)
RegisterNetEvent('fivem-appearance:barberMenu', function()
local config = {
ped = false,
headBlend = false,
faceFeatures = false,
headOverlays = true,
components = false,
props = false
}
exports['fivem-appearance']:startPlayerCustomization(function (appearance)
if appearance then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
else
print('Canceled')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
end
end, config)
end)
-- Backwords Events so you dont need to replace these
RegisterNetEvent('qb-clothing:client:openMenu', function() -- Admin Menu clothing event
Wait(500)
local config = {
ped = true,
headBlend = true,
faceFeatures = true,
headOverlays = true,
components = true,
props = true
}
exports['fivem-appearance']:startPlayerCustomization(function(appearance)
if appearance then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
else
print('Canceled')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
end
end, config)
end)
RegisterNetEvent('qb-clothing:client:openOutfitMenu', function() -- Name is so that you dont have to replace the event, Used in Appartments, Bossmenu, etc...
exports['qb-menu']:openMenu({
{
header = "👔 | Outfit Options",
isMenuHeader = true, -- Set to true to make a nonclickable title
},
{
header = "Change Outfit",
txt = "Pick from any of your currently saved outfits",
params = {
event = "fivem-appearance:pickNewOutfitApp",
args = {
number = 1,
id = 2
}
}
},
{
header = "Save New Outfit",
txt = "Save a new outfit you can use later on",
params = {
event = "fivem-appearance:saveOutfit",
}
},
{
header = "Delete Outfit",
txt = "Yeah... We didnt like that one either",
params = {
event = "fivem-appearance:deleteOutfitMenu",
args = {
number = 1,
id = 2
}
}
},
})
end)
RegisterNetEvent('fivem-appearance:pickNewOutfitApp', function(data)
local id = data.id
local number = data.number
TriggerEvent('fivem-appearance:getOutfits')
Wait(150)
local outfitMenu = {
{
header = '< Go Back',
params = {
event = 'qb-clothing:client:openOutfitMenu'
}
}
}
for i=1, #allMyOutfits, 1 do
outfitMenu[#outfitMenu + 1] = {
header = allMyOutfits[i].name,
params = {
event = 'fivem-appearance:setOutfit',
args = {
-- number = (1 + i),
ped = allMyOutfits[i].pedModel,
components = allMyOutfits[i].pedComponents,
props = allMyOutfits[i].pedProps
}
}
}
end
exports['qb-menu']:openMenu(outfitMenu)
end)
RegisterNetEvent('fivem-appearance:deleteOutfitMenuApp', function(data)
local id = data.id
local number = data.number
TriggerEvent('fivem-appearance:getOutfits')
Wait(150)
local DeleteMenu = {
{
header = '< Go Back',
params = {
event = 'fivem-appearance:clothingShop'
}
}
}
for i=1, #allMyOutfits, 1 do
DeleteMenu[#DeleteMenu + 1] = {
header = 'Delete "'..allMyOutfits[i].name..'"',
txt = 'You will never be able to get this back!',
params = {
event = 'fivem-appearance:deleteOutfit',
args = allMyOutfits[i].id
}
}
end
exports['qb-menu']:openMenu(DeleteMenu)
end)
-- Theads
CreateThread(function()
while true do
Wait(0)
if CurrentAction ~= nil then
if IsControlPressed(1, 38) then
Wait(500)
if CurrentAction == 'clothingMenu' then
TriggerEvent("fivem-appearance:clothingShop")
end
if CurrentAction == 'barberMenu' then
TriggerEvent("fivem-appearance:barberMenu")
end
end
end
end
end)
CreateThread(function()
for k,v in ipairs(Config.BarberShops) do
local blip = AddBlipForCoord(v)
SetBlipSprite (blip, 71)
-- SetBlipColour (blip, 47)
SetBlipScale (blip, 0.7)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName('Barber Shop')
EndTextCommandSetBlipName(blip)
end
for k,v in ipairs(Config.ClothingShops) do
local data = v
if data.blip == true then
local blip = AddBlipForCoord(data.coords)
SetBlipSprite (blip, 73)
-- SetBlipColour (blip, 47)
SetBlipScale (blip, 0.7)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName('Clothing Store')
EndTextCommandSetBlipName(blip)
end
end
end)
CreateThread(function()
while true do
local playerCoords, isInClothingShop, isInPDPresets, isInBarberShop, currentZone, letSleep = GetEntityCoords(PlayerPedId()), false, false, nil, true
local sleep = 2000
for k,v in pairs(Config.ClothingShops) do
local data = v
local distance = #(playerCoords - data.coords)
if distance < Config.DrawDistance then
sleep = 500
if distance < data.MarkerSize.x then
isInClothingShop, currentZone = true, k
end
end
end
for k,v in pairs(Config.BarberShops) do
local distance = #(playerCoords - v)
if distance < Config.DrawDistance then
sleep = 500
if distance < Config.MarkerSize.x then
isInBarberShop, currentZone = true, k
end
end
end
if (isInClothingShop and not hasAlreadyEnteredMarker) or (isInClothingShop and LastZone ~= currentZone) then
hasAlreadyEnteredMarker, LastZone = true, currentZone
CurrentAction = 'clothingMenu'
exports['qb-drawtext']:DrawText('[E] Clothing Menu','left')
end
if (isInBarberShop and not hasAlreadyEnteredMarker) or (isInBarberShop and LastZone ~= currentZone) then
hasAlreadyEnteredMarker, LastZone = true, currentZone
CurrentAction = 'barberMenu'
exports['qb-drawtext']:DrawText('[E] Barber Menu','left')
end
if not isInClothingShop and not isInBarberShop and hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = false
sleep = 0
TriggerEvent('fivem-appearance:hasExitedMarker', LastZone)
exports['qb-drawtext']:HideText()
end
Wait(sleep)
end
end)
-- Command(s)
RegisterCommand('reloadskin', function()
local playerPed = PlayerPedId()
local maxhealth = GetEntityMaxHealth(playerPed)
local health = GetEntityHealth(playerPed)
QBCore.Functions.TriggerCallback('fivem-appearance:getPlayerSkin', function(appearance)
exports['fivem-appearance']:setPlayerAppearance(appearance)
end)
for k, v in pairs(GetGamePool('CObject')) do
if IsEntityAttachedToEntity(PlayerPedId(), v) then
SetEntityAsMissionEntity(v, true, true)
DeleteObject(v)
DeleteEntity(v)
end
SetPedMaxHealth(PlayerId(), maxhealth)
Citizen.Wait(1000) -- Safety Delay
SetEntityHealth(PlayerPedId(), health)
end
end)
-- Testing Command
RegisterCommand('clothingmenu', function()
local config = {
ped = true,
headBlend = true,
faceFeatures = true,
headOverlays = true,
components = true,
props = true,
}
exports['fivem-appearance']:startPlayerCustomization(function (appearance)
if (appearance) then
TriggerServerEvent('fivem-appearance:save', appearance)
print('Player Clothing Saved')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
else
print('Canceled')
Wait(1000) -- Wait is needed to clothing menu dosent overwrite the tattoos
TriggerServerEvent('Select:Tattoos')
end
end, config)
end, false)
I tried to set the boundaries of the vectors, it did not help. Tried to find the error but couldn't...
The problem is that the CurrentAction variable is never being reset to nil, so the thread you started to monitor for that keypress continues to "react" to it with the last visited store.
The way the code is written, it appears as though it is meant to be reset to nil only when the when hasExitedMarker function is triggered, but you only trigger this in one place - and it is only conditionally run only if hasAlreadyEnteredMarker is set to true when a shop is detected as being exited. I have a feeling that variable is not being properly maintained.
You can see how this quickly turns into a daisy-chain of state that must be maintained "just so".
Without undergoing a massive debugging session on your behalf, I can only suggest you debug these variables by outputting them to the screen, and watching for when they are set and properly unset (or not).
Higher level advice might be to add whatever routine you use to detect entry/exit into barber/clothing shops to a standalone function you can call directly from the keypress event handler, and skip handling it if you are not in the expected location. This won't solve your original problem of your application state falling into disrepair, but it gives you a chance to "fix" your state on keypress if it turns out you are handling it when you shouldn't be.

how do i fix ')' (to close '(' at line 38), got '.'

for i, v in pairs(Buttons:GetChildren()) do
local NewItem = BoughtItems:FindFirstChild(v.Item.value)
if NewItem ~= nil then
Items[NewItem.Name] = NewItem:Clone()
NewItem:Destroy()
else
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillBoardGui.Frame.Visible = false
end
if v:FindFirstChild("Dependency") then
coroutine.resume(coroutine.create(function(
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillBoardGui.Frame.Visible = false
if BoughtItems:WaitForChild(v.Dependency.Value, 100000)then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true
v.ButtonPart.BillBoardGui.Frame.Visible = true
end
end))
end
v.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid")then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == Player then
if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
if Player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then
Player.leaderstats.Cash.Value -= v.Price.Value
Items[v.Item.Value].Parent = BoughtItems
v:Destroy()
end
end
end
end
end)
end
how do i fix this the header is the problem i dont knw what it means so is there a fix to it for my tycoon if anyone knows pls comment (heres some random stuff since my post is mostly code) A brief Introduction to Copypasta. Copypasta means to copy a text or a part of the text from an existing manuscript and inclusion of that very text in an under-process manuscript by pasting. At present, the societies are going to be expanded with an enormous pattern.
Parenthesis always come in pairs. The error message already strongly suggests that you are missing a closing parenthesis for an opening one in line 38.
1 2 3
coroutine.resume(coroutine.create(function(
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillBoardGui.Frame.Visible = false
if BoughtItems:WaitForChild(v.Dependency.Value, 100000)then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true
v.ButtonPart.BillBoardGui.Frame.Visible = true
end
end)) <--- one is missing
1 2
Use a text editor that autocompletes pairs or even better one that hightlights pairs in matching colors to avoid errors like this.

Proximity prompt issue

basically after my math.random it will teleport you to a location and then after 20 seconds it will teleport you back. The proximity prompt that this script is in only fires this script once, i click the button to go to sleep and it does nothing, no error code no thing. On the other hand after the else statement i can click the button three separate times and then if i try clicking it a fourth time it no longer works, still with no error.
Is there anyway I can fix this?
Heres my code if helpful
game.Players.PlayerAdded:Connect(function(player)
script.Parent.Triggered:Connect(function(activated)
if activated then
print("activated")
if game.ReplicatedFirst.night.Value == true then
script.Parent.Enabled = false
local number = math.random(1, 2)
print(number)
if number == 1 then
local plr = game.Workspace:FindFirstChild(player.Name)
game.ReplicatedFirst.slep.Value = true
plr.Humanoid.HipHeight = -0.913
plr.HumanoidRootPart.Position = Vector3.new(327.227, 1.5, -348.899) + Vector3.new(0,10,0)
print("ho")
player.PlayerGui.slepgui.Enabled = false
wait(20)
game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.Position = Vector3.new(31.546, 20.793, 12.62) + Vector3.new(0,10,0)
script.Parent.Enabled = true
game.ReplicatedFirst.night.Value = false
game.ReplicatedFirst.slep.Value = false
game.Workspace["Hotel - undertale"].Playing = true
game.Lighting.TimeOfDay = 12
else
local plr = game.Workspace:FindFirstChild(player.Name)
player.PlayerGui.slepgui.Enabled = true
script.Parent.Enabled = false
game.ReplicatedFirst.slep.Value = true
script.Parent.ObjectText = "Go to bed, this will skip the night"
game.Workspace["SNORING - SOUND EFFECT (128 kbps)"].Playing = true
print("number one worked")
wait(12)
plr.HumanoidRootPart.Position = Vector3.new(31.546, 20.793, 12.62) + Vector3.new(0,10,0)
game.ReplicatedFirst.night.Value = false
game.ReplicatedFirst.slep.Value = false
game.Workspace["Hotel - undertale"].Playing = true
player.PlayerGui.slepgui.Enabled = false
script.Parent.Enabled = true
game.Lighting.TimeOfDay = 12
script.Parent.ObjectText = "Go to bed. Only avaliable at night"
print("Numver two worked")
end
end
end
end)
end)
-- 327.227, 1.5, -348.899

Why is it that when I set a new variable to the player entity FindMetaTable("Player") on the server side, but is 'nil' on the client side?

To clarify, because it was hard to explain in the title.
-- file that contains this code is > "player.lua"
local ply = FindMetaTable("Player")
ply.LastDamageType = "N/A"
this code sets a new variable to all player entities. The variable is just a string of the last entity that did damage to the player. That is made possible by the following code:
-- file that contains this code is > "init.lua"
AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init.lua")
include("shared.lua")
include("player.lua")
-->
--> OTHER METHODS THAT I DIDN'T INCLUDE
-->
function GM:PlayerShouldTakeDamage(ply, attacker)
ply.LastDamageType=tostring(attacker)
return true
end
My point of doing all this is because I want to have a hud element that will display this string so the client can see what was the last thing that dealt damage to him.
The problem is that, the variable is coming up as nil on the client side file "cl_init", yet if I printed the table that contained all the data that was in the player through the client AND through the server side. both tables were the same excluding the variable I made "LastDamageType"
-- file that contains this code is > "cl_init.lua"
include("shared.lua")
surface.CreateFont("dayz_font",{font="Arial",size=24,weight=400})
function GM:HUDPaint()
local ply = LocalPlayer()
draw.SimpleText("you are "..ply:Nick(),"dayz_font", 150,10,Color(255,120,50),TEXT_ALIGN_CENTER)//TargetID
surface.SetFont("TargetID")
surface.SetTextColor(Color(30,70,130))
surface.SetTextPos(surface.ScreenWidth()-200 ,20)
surface.DrawText("You have ")
surface.SetTextColor(Color(200,90,30))
surface.DrawText(ply:Health())
surface.SetTextColor(Color(30,70,130))
surface.DrawText(" health")
surface.SetTextPos(surface.ScreenWidth()-200 ,35)
surface.DrawText(""..tostring(Entity(1):GetTable().LastDamageType))
-- FOR DEBUGGING PURPOSES, I'M USING "Entity(1)" TO GET MY PLAYER
-- I KNOW THAT "LocalPlayer()" PROBABLY ALSO EQUATES TO THE SAME THING
-- AS WHAT "Entity(1)" IS AT THIS MOMENT BECAUSE I'M TESTING THIS IN SINGLEPLAYER.
end
So it seems that the player data on the client side and the server side are not the SAME thing and that they have to be synchronized or something like that... Or did I miss something important that kept them synchronized?
//////////////////////////////////////////////////
ADDITIONAL INFORMATION
//////////////////////////////////////////////////
These are printed lists of all the variables of my player entity when I did
PrintTable(Entity(1):GetTable())
on both the client side and server side. The first list is on the server and the second is on the client. I will separate them with ==========================
I know you don't probably want to look through the list to just to Ctrl+F and type in "LastDamageType" to highlight it.
/////////////////////////////////////////
SERVER SIDE
CWAttachments:
am_flechetterounds = true
am_magnum = true
am_matchgrade = true
am_slugrounds = true
bg_ak74_rpkbarrel = true
bg_ak74_ubarrel = true
bg_ak74foldablestock = true
bg_ak74heavystock = true
bg_ak74rpkmag = true
bg_ar1560rndmag = true
bg_ar15heavystock = true
bg_ar15sturdystock = true
bg_bipod = true
bg_deagle_compensator = true
bg_deagle_extendedbarrel = true
bg_foldsight = true
bg_longbarrel = true
bg_longbarrelmr96 = true
bg_longris = true
bg_magpulhandguard = true
bg_mp530rndmag = true
bg_mp5_kbarrel = true
bg_mp5_sdbarrel = true
bg_nostock = true
bg_regularbarrel = true
bg_retractablestock = true
bg_ris = true
bg_sg1scope = true
md_acog = true
md_aimpoint = true
md_anpeq15 = true
md_cobram2 = true
md_eotech = true
md_foregrip = true
md_kobra = true
md_m203 = true
md_microt1 = true
md_pbs1 = true
md_pso1 = true
md_saker = true
md_tundra9mm = true
CalcIdeal = 990
CalcSeqOverride = -1
DTVar = function: 0x1ca93680
EditValue = function: 0x2ac6c878
GetEditingData = function: 0x18501238
GetNetworkKeyValue = function: 0x1caf7ec0
GetNetworkVars = function: 0x1caf9640
LastDamageType = Entity [0][worldspawn]
LastPlayerTrace = 859.94995117188
LastSpawnpoint = Entity [61][info_player_start]
NetworkVar = function: 0x2375b100
NetworkVarElement = function: 0x23785a08
NetworkVarNotify = function: 0x1844e3c8
PlayerTrace:
Entity = Entity [0][worldspawn]
Fraction = 0.49089023470879
FractionLeftSolid = 0
Hit = true
HitBox = 0
HitGroup = 0
HitNoDraw = false
HitNonWorld = false
HitNormal = -1.000000 0.000000 0.000000
HitPos = 15359.968750 950.995850 -12563.697266
HitSky = true
HitTexture = TOOLS/TOOLSSKYBOX
HitWorld = true
MatType = 88
Normal = 0.998662 0.047185 -0.021163
PhysicsBone = 0
StartPos = -704.000000 192.000000 -12223.280273
StartSolid = false
SurfaceProps = 77
RestoreNetworkVars = function: 0x184b21a8
SCarMouseMoveX = 0
SCarMouseMoveY = 0
SetNetworkKeyValue = function: 0x1838a3f8
SetupEditing = function: 0x0f107ab8
SetupKeyValue = function: 0x1844da70
WT_RagdollRoper_Roping = false
canChat = 864.94995117188
dt:
m_CurrentPlayerClass:
ClassID = 125
Func = function: 0x1ca70b58
Player = Player [1][UbErZ Andrew900460]
m_bFlashlight = true
m_bInSwim = false
m_bWasNoclipping = false
m_bWasOnGround = true
////////////////////////////////////////////////////////////////
CLIENT SIDE
CWAttachments:
am_flechetterounds = true
am_magnum = true
am_matchgrade = true
am_slugrounds = true
bg_ak74_rpkbarrel = true
bg_ak74_ubarrel = true
bg_ak74foldablestock = true
bg_ak74heavystock = true
bg_ak74rpkmag = true
bg_ar1560rndmag = true
bg_ar15heavystock = true
bg_ar15sturdystock = true
bg_bipod = true
bg_deagle_compensator = true
bg_deagle_extendedbarrel = true
bg_foldsight = true
bg_longbarrel = true
bg_longbarrelmr96 = true
bg_longris = true
bg_magpulhandguard = true
bg_mp530rndmag = true
bg_mp5_kbarrel = true
bg_mp5_sdbarrel = true
bg_nostock = true
bg_regularbarrel = true
bg_retractablestock = true
bg_ris = true
bg_sg1scope = true
md_acog = true
md_aimpoint = true
md_anpeq15 = true
md_cobram2 = true
md_eotech = true
md_foregrip = true
md_kobra = true
md_m203 = true
md_microt1 = true
md_pbs1 = true
md_pso1 = true
md_saker = true
md_tundra9mm = true
CalcIdeal = 990
CalcSeqOverride = -1
ChatGestureWeight = 0
DTVar = function: 0x2be3b410
EditValue = function: 0x3053c750
GetEditingData = function: 0x2bb01b30
GetNetworkKeyValue = function: 0x2bb01d18
GetNetworkVars = function: 0x2bb01d38
LastPlayerTrace = 859.96203613281
NetworkVar = function: 0x2bb01c98
NetworkVarElement = function: 0x2bab5340
NetworkVarNotify = function: 0x2bb01cd8
PlayerTrace:
Entity = Entity [0][worldspawn]
Fraction = 0.49089023470879
FractionLeftSolid = 0
Hit = true
HitBox = 0
HitGroup = 0
HitNoDraw = false
HitNonWorld = false
HitNormal = -1.000000 0.000000 0.000000
HitPos = 15359.968750 950.995850 -12563.697266
HitSky = true
HitTexture = TOOLS/TOOLSSKYBOX
HitWorld = true
MatType = 88
Normal = 0.998662 0.047185 -0.021163
PhysicsBone = 0
StartPos = -704.000000 192.000000 -12223.280273
StartSolid = false
SurfaceProps = 77
RestoreNetworkVars = function: 0x2bb01d58
SetNetworkKeyValue = function: 0x2bb01cf8
SetupEditing = function: 0x2bb01c38
SetupKeyValue = function: 0x2bb01c58
dt:
m_CurrentPlayerClass:
ClassID = 125
Func = function: 0x30283ff8
Player = Player [1][UbErZ Andrew900460]
m_bInSwim = false
m_bWasNoclipping = false
m_bWasOnGround = true
If you wish to have a network shared variable that you can assign to an entity (e.g. a player) you want to use NWVariables. In your situation, since you are saving an entity you want to look at SetNWEntity and GetNWEntity.
Here is how you would implement it in the PlayerShouldTakeDamage hook:
function GM:PlayerShouldTakeDamage(ply, attacker)
ply:SetNWEntity("LastDamageType", attacker)
return true
end

Resources