Server:
rEvents.addApple.OnServerEvent:connect(function(plr)
local appleAmount = 15
local appleValue = plr.Apples
plr.Apples.Value += module.addApple(appleAmount, appleValue)
end)
Server:
rEvents.addApple.OnServerEvent:connect(function(plr)
local appleAmount = 15
local appleValue = plr.Apples
plr.Apples.Value += module.addApple(appleAmount, appleValue)
end)
But what is appleAmount used for (in the module) as I canât see it being used in the scripts provided (unless Iâm blind)
Without += works =
With += error
local remainingApple = appleValue.Value + appleAmount.
So I guess use that if it works and the other doesnât not sure why though
It says
appleValue.Value + appleValue
In the code you provided
Yeah but then people canât gain any value which is will stuck at 0 forever, since when youâre collecting it should has + instead just =
I fixed it since I made the mistake, it shouldât be the 2 same values at all XD
So it works now?
30 happy roblox
No, I wish if it was worked, still the same issue but at least now it prints appleAmount(15) and the players apple value, but still broken. For example youâre only able to collect the 1 apple, youâre getting + X value from module and it being broken without any reason with the error. So you should reset or just rejoin which is makes me confused.
Can you put the updated code please
Module:
local module = {
addApple = function(appleAmount, appleValue)
if appleAmount ~= nil and appleValue ~= nil then
local remainingApple = appleValue.Value + appleAmount
if remainingApple > 0 then
applesCollected(appleValue, remainingApple)
else
appleValue.Value = remainingApple
end
end
end
}
return module
Server:
rEvents.addApple.OnServerEvent:connect(function(plr)
local appleAmount = 15
local appleValue = plr.Apples
plr.Apples.Value += module.addApple(appleAmount, appleValue)
end)
Well remainingapples will never be less than 0 because you are adding 15 apples
So can I please see the applesCollected function
Thatâs why it should be always > 0 so itâs fine
Can I please see the applesCollected
Your problem is here, looks like youâre adding appleValue which seems to be an Instance to that same isntanceâs value, did you mean
local remainingApple = appleValue.Value + appleAmount
Pretty sure the guy before said this.
It could also be the applesCollected function, since a number + Instance would be nil, but not sure what that function does
Why donât you always do
appleValue.Value = remainingApple
Yes we have got that issue fixed the new code is a few posts above your post
âââ
local function applesCollected(appleValue)
local leftOverApple = 0
local newApple = 1
local loopStartTime = tick()
repeat
leftOverApple = remainingApple
if leftOverApple >= 0 then
local continueApple = true
if appleValue ~= nil then
continueApple = false
end
if continueApple == true then
newApple = newApple + 1
remainingApple = leftOverApple
else
remainingApple = 0
leftOverApple = 0
appleValue.Value = newApple
break
end
else
appleValue.Value = remainingApple
break
end
until leftOverApple < 0 or leftOverApple < 0
local loopAfterTime = tick()
local totalLoopTime = loopAfterTime - loopStartTime
if totalLoopTime >= 0.5 then
warn("Apple loop time above 0.5 seconds: " ⌠tostring(totalLoopTime))
end
end
âââ