Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Value changes, but ModuleScript uses original value?

Asked by 7 years ago

I'm making a MMORPG shooter game. I have weapons that have a Configuration folder inside them, which have values. A ModuleScript will recognize these values and make them have use (such as damage, reload time, spread, etc.), but once they change, the ModuleScript won't use the new value and will use the original value. How can I make it recognize the new value?

CODE SNIPPETS (Separated)

1local reloadtime = script.Parent.WeaponStats.ReloadTime
1ReloadTime = reloadtime.Value
1ReloadAnimationSpeed = reloadtime.Value + 0.2

(end) If you know what FE Gun Kit (by SuperEvilAzmil) is and you are fluent with values, i'm pretty sure you can help. You don't need to know what the gun kit is. (requested help on the unoffical roblox discord, but that didn't help me well.)

0
The issue is that you need to re-define the reloadtime variable, or it'll keep using the old one. Like sweetkid suggested, make a function that detects when the variable has been changed, then redefine it via the function. EnderGamer358 79 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Variables connected to properties don't change when their corresponding property changes. Use this to help.

1-- local reloadtime = script.Parent.WeaponStats.ReloadTime
2-- ReloadTime = reloadtime.Value
3-- ReloadAnimationSpeed = reloadtime.Value + 0.2
4reloadtime.Changed:Connect(function()
5    ReloadTime = reloadtime.Value
6    ReloadAnimationSpeed = reloadtime.Value + 0.2
7end)

EDIT: Still won't change? Weird, try this

01-- local reloadtime = script.Parent.WeaponStats.ReloadTime
02-- ReloadTime = reloadtime.Value
03-- ReloadAnimationSpeed = reloadtime.Value + 0.2
04local UpdateCoroutine = coroutine.create(function()
05    while true do
06        ReloadTime = reloadtime.Value
07        ReloadAnimationSpeed = reloadtime.Value + 0.2
08        wait()
09    end
10end)
11coroutine.resume(UpdateCoroutine)

EDIT EDIT: Still doesn't work??? nani?

here goes

01-- at the start of the script
02local reloadtime = script.Parent.WeaponStats.ReloadTime
03local UpdateCoroutine = coroutine.create(function()
04    while true do
05        ReloadTime = script.Parent.WeaponStats.ReloadTime.Value
06        ReloadAnimationSpeed = script.Parent.WeaponStats.ReloadTime.Value + 0.2
07        wait()
08    end
09end
10coroutine.resume(UpdateCoroutine)

if this still doesn't work, it's not at the start of the script

if it still doesn't work at the start of the script, you misspelled something

if you copied it directly from the view source thingy that always is included with the lua thingy and it still doesn't work, then

01while true do
02    spawn(function()
03        while true do
04            spawn(function()
05                spawn(function()
06                    while true do
07                        print("NANI?")
08                    end
09                while true do
10                    print("NANI?")
11                end
12            while true do
13                spawn(function()
14                    while true do
15                        print("NANI?")
View all 44 lines...

IT DIDN'T WORK?????

01while true do
02    local corout = coroutine.create(function()
03        while true do
04            local corou = coroutine.create(function()
05                while true do
06                    local coro = coroutine.create(function()
07                        while true do
08                            local cor = coroutine.create(function()
09                                while true do
10                                    local co = coroutine.create(function()
11                                        print("NANI?")
12                                    end)
13                                    coroutine.resume(co)
14                                    print("NANI?")
15                                end
View all 31 lines...
0
It still won't change. Can you try something else? ShutokouBattle 227 — 7y
0
Still won't work! Roblox really hates me. I'm sorry if I annoy you, but can you just try one more time? ShutokouBattle 227 — 7y
0
nope it still won't work. going to find more people how to fix this. ShutokouBattle 227 — 7y
0
Doesn't work? yea something's fishy here sweetkid01 176 — 7y
Ad

Answer this question