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 6 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)

local reloadtime = script.Parent.WeaponStats.ReloadTime
ReloadTime = reloadtime.Value
ReloadAnimationSpeed = 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 — 6y

1 answer

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

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

-- local reloadtime = script.Parent.WeaponStats.ReloadTime
-- ReloadTime = reloadtime.Value
-- ReloadAnimationSpeed = reloadtime.Value + 0.2
reloadtime.Changed:Connect(function()
    ReloadTime = reloadtime.Value
    ReloadAnimationSpeed = reloadtime.Value + 0.2
end)

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

-- local reloadtime = script.Parent.WeaponStats.ReloadTime
-- ReloadTime = reloadtime.Value
-- ReloadAnimationSpeed = reloadtime.Value + 0.2
local UpdateCoroutine = coroutine.create(function()
    while true do
        ReloadTime = reloadtime.Value
        ReloadAnimationSpeed = reloadtime.Value + 0.2
        wait()
    end
end)
coroutine.resume(UpdateCoroutine)

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

here goes

-- at the start of the script
local reloadtime = script.Parent.WeaponStats.ReloadTime
local UpdateCoroutine = coroutine.create(function()
    while true do
        ReloadTime = script.Parent.WeaponStats.ReloadTime.Value
        ReloadAnimationSpeed = script.Parent.WeaponStats.ReloadTime.Value + 0.2
        wait()
    end
end
coroutine.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

while true do
    spawn(function()
        while true do
            spawn(function()
                spawn(function()
                    while true do
                        print("NANI?")
                    end
                while true do
                    print("NANI?")
                end
            while true do
                spawn(function()
                    while true do
                        print("NANI?")
                    end
                end
                while true do
                    print("NANI?")
                end
            end
        end
    end
    while true do
        spawn(function()
            spawn(function()
                while true do
                    print("NANI?")
                end
            while true do
                print("NANI?")
            end
        while true do
            spawn(function()
                while true do
                    print("NANI?")
                end
            end
            while true do
                print("NANI?")
            end
        end
    end
end

IT DIDN'T WORK?????

while true do
    local corout = coroutine.create(function()
        while true do
            local corou = coroutine.create(function()
                while true do
                    local coro = coroutine.create(function()
                        while true do
                            local cor = coroutine.create(function()
                                while true do
                                    local co = coroutine.create(function()
                                        print("NANI?")
                                    end)
                                    coroutine.resume(co)
                                    print("NANI?")
                                end
                            end)
                            coroutine.resume(cor)
                            print("NANI?")
                        end
                    end)
                    coroutine.resume(coro)
                    print("NANI?")
                end
            end)
            coroutine.resume(corou)
            print("NANI?")
        end
    end)
    coroutine.resume(corout)
    print("NANI?")
end
0
It still won't change. Can you try something else? ShutokouBattle 227 — 6y
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 — 6y
0
nope it still won't work. going to find more people how to fix this. ShutokouBattle 227 — 6y
0
Doesn't work? yea something's fishy here sweetkid01 176 — 6y
Ad

Answer this question