I am looking in the studio at the object itself while the script cannot find it. I’ve got no idea why it doesn’t work. I am going to look at the typing and the .Parent since that has some problems sometimes.
It looks like you are trying to set the value of the DeliveryTime property of the Currency folder within the plr object to the value of the ReplacementValue property of the Replacements folder within the plr object.
The error message “Infinite yield possible on script” suggests that there is a potential infinite loop in your code. This can happen if the script that is running after the value is created ( plr:WaitForChild("Currency"):WaitForChild("DeliveryTime").Value = plr:WaitForChild("Replacements"):WaitForChild("ReplacementValue").Value ) is being called repeatedly without the ReplacementValue being set to a different value.
To troubleshoot this issue, I would recommend adding some print statements to your code to see what is happening at each step. You can also try adding a delay (using the wait function) between the creation of the ReplacementValue and the setting of the DeliveryTime value to see if that resolves the issue.
I hope this helps! Let me know if you have any other questions.
To fix the issue with your code, you will need to determine what is causing the potential infinite loop. One way to do this is to add some print statements to your code to see what is happening at each step.
For example, you could try adding the following lines of code at the beginning and end of each script.
print("Start of script")
-- your code here
print("End of script")
This will help you see how many times the scripts are being run, and whether the ReplacementValue is being set to a new value between each iteration.
You can also try adding a delay (using the wait function) between the creation of the ReplacementValue and the setting of the DeliveryTime value to see if that resolves the issue. For example.
local replacements = Instance.new("Folder",plr)
replacements.Name = "Replacements"
if Replacements:FindFirstChild("ReplacementValue") then
Replacements.ReplacementValue:Destroy()
wait(0.1)
local replacementvalue = Instance.new("NumberValue")
replacementvalue.Name = "ReplacementValue"
replacementvalue.Value = deliverytime
replacementvalue.Parent = player:WaitForChild("Replacements")
else
local replacementvalue = Instance.new("NumberValue")
replacementvalue.Name = "ReplacementValue"
replacementvalue.Value = deliverytime
replacementvalue.Parent = player:WaitForChild("Replacements")
end
wait(0.1)
plr:WaitForChild("Currency"):WaitForChild("DeliveryTime").Value = plr:WaitForChild("Replacements"):WaitForChild("ReplacementValue").Value
I hope this helps! Let me know if you have any other questions.
I’ve checked everything that happens on each line, and nothing loops. ReplacementValue is totally fine, it works perfectly, I also can’t see anything wrong with the typing.
About placing a timing between them, I also did that but I’ve got the same error.
I am using this value in my game as a value to save when the player chooses between some items. There are 3 options and everytime the player clicks on one of them, the old (if exists) ReplacementValue gets deleted and replaced with a new one. Then when the player is happy with his option, he clicks on a button that triggers an event that goes to a different script (Note: everything works great till now, starting from the next phrase stuff goes wrong). That’s where the DeliveryTime value gets changed to the ReplacementValue.
It sounds like you have checked all of the individual lines of code and determined that the issue may be with how the ReplacementValue is being used in the other script.
One potential issue could be that the ReplacementValue is not being properly passed to the other script. You can try adding a print statement to the other script to verify that the ReplacementValue is being correctly passed and received.
Another potential issue could be that the other script is not properly accessing the ReplacementValue. Make sure that the script is correctly accessing the player’s Replacements folder and the ReplacementValue within it.
I’ve tried to use if statements to make sure the value is not already created, but it just doesn’t work.
The problem is here: if Replacements:FindFirstChild(“ReplacementValue”) then
Replacements.ReplacementValue:Destroy()
You are trying to destroy the ReplacementValue before you even create it. So you are trying to destroy a non-existant value, which is why it is not working. You should do one of these: if Replacements:FindFirstChild(“ReplacementValue”) then
Replacements:FindFirstChild(“ReplacementValue”):Destroy()
Or: local replacementvalue = Instance.new(“NumberValue”)
replacementvalue.Name = “ReplacementValue”
replacementvalue.Value = deliverytime
replacementvalue.Parent = player:WaitForChild(“Replacements”)
if Replacements:FindFirstChild(“ReplacementValue”) then
ReplacementValue:Destroy()
end