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

Why is this local script not detecting the change in this module script?

Asked by 3 years ago

So infection game right? I need a table to store all infected characters. I create a module script in ReplicatedStorage ( the local script in StarterPlayerScripts needs to access the table as well) to store a table and make the regular script to set characters in the table to true when they're infected.

local function explode1(character,WaitTime)

local Head = character:FindFirstChild("Head")
local Humanoid = character:FindFirstChild("Humanoid")
local player = Players:GetPlayerFromCharacter(character)

--Does the character have a head and humanoid?
if not Head or not Humanoid then
    return
end
--Is the character already infected?
if usefulStuff.InfectedCharacters[character.Name] == true then 
    return
end

usefulStuff.InfectedCharacters[character.Name] = true -- Changes character to true in table

etc.

Then, if the character belongs to a player, it fires a remote event to change some Gui stuff on the player screen to let them know they are infected.


if player then
        RemoteEvents.Explode.Explode1:FireClient(player,WaitTime)
    else
        wait(math.random(WaitTime*0.5,WaitTime))
        explode2(character,10)
    end

Then in the local script, the GUI change stuff is fine, but I want to player to be able to explode their head with "E" before the timer ends. So, when "E" is pressed, I check if the player is infected before exploding.


(This is a local script btw)

Input.InputBegan:Connect(function(input,gameProcessed)
    local ignitedBool = player.ignitedBool
    print(usefulStuff.InfectedCharacters[player.Character]) 
-- this prints out nil even though I changed the value to true in the original script?
    if input.KeyCode == Enum.KeyCode.E and ignitedBool.Value == false and usefulStuff.InfectedCharacters[player.Character] then
        ignitedBool.Value = true
        local CDB = player.PlayerGui:WaitForChild("InfectionGui"):WaitForChild("CountDownBox")
        CDB.Text = "  Igniting in: 0  "
        hideCDB()
        RemoteEvents.Explode.Explode2:FireServer(player.Character,10)
    end
end)

However, the local script for some reason doesn't realize that the character in the table is true, so it doesn't fire the code.

So do module scripts just not work with local scripts? Do local scripts not detect changes in a table in a module script for some reason? Should I just scrap this module script idea and just add a bool value to each character instead? I pray to the Roblox scripting gods for help.

(Sorry if this was long or confusing)

0
maybe try a normal script not a local script minishyft -25 — 3y

Answer this question