Value of my variables won't update on my script - roblox

i am making a simulator map when you have to refill your backpack
to refill my backpack i copy the value of the capacity of my backpack but if i change the value of the capacity of backpack variable, it won't refresh the value and give the first value.
local db = false
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if not db then
db =true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.data.Mail.Value = 0
plr.data.Mail.Value = plr.data.Backpack.Value
script.Parent.Sound:Play()
wait(1)
db = false
end
end
end)
thank you if you can help me !

plr.data.Backpack is not a variable, it is an object, you could name a variable an item you gave a value inside your script, such as "local db = false", this is a variable.
There is few ways of changing value in roblox, if you changed a value from your client while testing (debuging) changes won't appear, you would need to switch to server-side of current debug session in your roblox studio or use a server console to execute the code.
Try to debug by writing this into your event function somewhere in the end
local val = 243453543 --replace with some value
plr.data.Backpack.Value = val
if everything is correct you should see the value of 'val' variable as a value of plr.data.Backpack, you can check it in your explorer, there is also no needs to write plr.data.Mail.Value = 0 row because you are changing the value again without any other methods, values doesn't need to be cleared.
So in the end you should have:
local db = false
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if not db then
db =true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.data.Mail.Value = plr.data.Backpack.Value
script.Parent.Sound:Play()
wait(1)
local val = 243453543
plr.data.Backpack.Value = val
db = false
end
end
end)
Also check plr.data.Backpack.className is "NumberValue" in explorer.

Related

Unable to make schedule.do function and global variable work together

I want a few jobs executed everyday at specific times.
The first job I want to run is to acquire data from the database and store it in a global variable
The second job I want to run is a few minutes after the first job is executed where it uses the data acquired from the first job that was stored in a global variable.
global dataacq
dataacq = None
def condb():
global check
global dataacq
conn = psycopg2.connect(#someinformation)
cursor = conn.cursor()
query = "SELECT conversation_id FROM tablename"
cursor.execute(query)
dataacq = cursor.fetchall()
print(dataacq)
cursor.close()
conn.close()
check = True
print(check)
return dataacq
def printresult(result):
print(result)
schedule.every().day.at("08:59").do(condb)
schedule.every().day.at("09:00").do(printresult, dataacq)
Above is a part of the code I am using for testing. The problem here is when the "printresult" function is called it displays None as output. But if I execute all the functions without any scheduling then it works and displays what I need it to show. So why is this happening?

Roblox remoteevents change value

local script
function Click(player)
if game.Workspace.Folder.Value == 0 then local num = 1
elseif game.Workspace.Folder.Value == 1 then local num = 0
game.ReplicatedStorage.Test:FireServer(player ,num)
end
script.Parent.ClickDetector.MouseClick:connect(Click)
end
server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.Test.OnServerEvent:Connect(function(player ,num)
if player:GetRankInGroup(1) > 248 then
game.Workspace.Folder.Value = num
else
end
end
)
Doesn't work at all, tried testing if it even connects by printing stuff.
You have a bunch of issues.
1. LocalScripts only run in a few locations, and the Workspace isn't one of them.
Based on your code, I'm assuming this LocalScript is a child of a ClickDetector in the Workspace.
See the docs for LocalScripts :
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
A Player’s Backpack, such as a child of a Tool
A Player’s character model
A Player’s PlayerGui
A Player’s PlayerScripts.
The ReplicatedFirst service
So you need to move the LocalScript to a location where it will actually run, then update the path to the ClickDetector.
-- find the detector in the Workspace
local detector = game.Workspace.Part.ClickDetector
detector.MouseClick:Connect(Click)
2. The connection is inside a function that never gets called.
This looks like a typo, but the line where the MouseClick signal is connected to happens inside the Click function, not outside. So effectively, the Click function is declared and never called by anything. You need to move it outside the last end
3. Variables declared using `local` are only accessible at the level (or deeper) that they are declared at.
Let me annotate your code to highlight what's happening...
local function Click(player)
if game.Workspace.Folder.Value == 0 then
local num = 1
-- num stops existing here and Test is never fired
elseif game.Workspace.Folder.Value == 1 then
local num = 0
game.ReplicatedStorage.Test:FireServer(num)
-- Test is fired with a value of 0 only when Folder.Value equals 1
end
end
local detector = game.Workspace.Part.ClickDetector
detector.MouseClick:Connect(Click)
To fix this, you need to move the local num declaration to a higher scope so it is encapsulates the if-statement. Then you need to make sure that the Remote event is fired in both cases, so you should move it outside the if-statement...
function Click(player)
-- define num
local num
if game.Workspace.Folder.Value == 0 then
num = 1
else --if game.Workspace.Folder.Value == 1 then
num = 0
end
-- fire the RemoteEvent
game.ReplicatedStorage.Test:FireServer(num)
end
local detector = game.Workspace.Part.ClickDetector
detector.MouseClick:Connect(Click)
4. (Nit-pick) Bad tabbing in your server Script creates confusion
This is not something you need to fix, but as atomfrog pointed out, nothing is happening in your Script's else block. It is unnecessary to have it at all, and it looks like you tried to use end to escape from the Script, but all you've done is indented your if-statement incorrectly. If you want to escape or for nothing to happen, use return, or don't have an else block.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.Test.OnServerEvent:Connect( function(player, num)
local specialGroupId = 1
local lowestPermissionLevel = 248
if player:GetRankInGroup(specialGroupId) > lowestPermissionLevel then
game.Workspace.Folder.Value = num
end
end)
maybe it doesn't work because you have nothing after the else

Store a fixed value in the variable only once

I have a variable in my code called p_fix. It is necessary to save the value of this variable when PE>p. But the way I did it, every time PE>p is respected, the value of this variable is changed, how can I save its value only once when PE>p and never change the value of this variable (p_fix) again?
for n = 1:size(t,1)
if n>=4
X = [Ia(n-1,1) Ia(n-2,1) ; Ia(n-2,1) Ia(n-3,1)];
future = [Ia(n,1) ; Ia(n-1,1)];
C = X\future;
Ia_future(n,1) = C(1,1)*Ia(n,1)+C(2,1)*Ia(n-1,1);
PE(n,1)=Ia(n,1)+Ia_future(n,1);
p(n,1)=(1+0.2)*max(PE(n-1,1));
if PE(n-1,1)>p(n,1)
p_fix = p(n,1);
end
end
end
You can either:
Before the loop, initialize p_fix to an empty array, and only set it if it’s empty:
if isempty(p_fix) && PE(n-1,1)>p(n,1)
p_fix = p(n,1);
end
Or use a second Boolean variable, for example done, that keeps track of whether you’ve set your other variable or not. Initialize it to false before the loop, then:
if ~done && PE(n-1,1)>p(n,1)
p_fix = p(n,1);
done = true;
end

ROBLOX INFINITE YIELD Infinite yield possible on 'Players.Aiman123boss.PlayerGui:WaitForChild("Main")'

i get this infinte yield:
Infinite yield possible on 'Players.Aiman123boss.PlayerGui:WaitForChild("Main")'
i want to fix it so heres my script:
local pg = player:WaitForChild("PlayerGui")
local Main = pg:WaitForChild("Main")
for i, v in pairs(Main.PetShop.ScrollingFrame:GetChildren()) do
if v.Name ~= "Template" and v:IsA("Frame") then
v.PetPrice.Text = game.ServerStorage:WaitForChild("Pets"):FindFirstChild(v.Name).Price.Value
v.PetName.Text = game.ServerStorage:WaitForChild("Pets"):FindFirstChild(v.Name).Name
end
end
You are waiting on the object "Main" here:
local Main = pg:WaitForChild("Main")
Roblox determined that it's possible that "Main" will never be found, because the object doesn't exist completely. Try checking your object hierarchy and determine if the following path exists:
game.StarterGui.Main
If it exists, check if there's any script that might destroy the GUI.

convert simple VB script to MATLAB

I have some problem converting simples VB scripts (formating) into MATLAB:
VB script:
Range("A1").Select
Selection.Font.Italic = True
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
End With
I tried:
xlswrite('test.xls',1,'A1');
Excel = actxserver('Excel.Application');
Excel.Workbooks.Open('test.xls');
Range = Excel.Range('A1');
Range.Font.Italic = True; % Doesnt work
Range.Border.Item('xlEdgeRight').LineStyle = 1; % Doesnt work
Excel.Visible = 1;
Any workaround? Thanks
The problem is probably this line:
Range = Excel.Range('A1');
Your Excel object is an Application object, which doesn't have a Range property. The VBA example you follow uses a (IMHO) poor practice of using the global default objects that are only available within the context of the application itself. You need to grab a reference to the Workbook returned by this call:
Excel.Workbooks.Open('test.xls');
After that, you need to get the worksheet from it's indexed Worksheets property, then get the Range from that. Also, "xlEdgeRight" is an enumeration member so external calls have to use the integer values for them instead of a string. You can replace xlEdgeRight with 10.
I know next to nothing about Matlab, but this is what the more explicit code would look like in VBA:
Dim book As Workbook, sheet As Worksheet, rng As Range
Set book = Application.Workbooks.Open("test.xls")
Set sheet = book.Worksheets("Sheet1")
Set rng = sheet.Range("A1")
rng.Font.Italic = True
rng.Borders.Item(10).LineStyle = 1
You should be able to get it from there.