#Script sometimes just does not work

1 messages · Page 1 of 1 (latest)

crimson knot
#

Sometimes when I join the game in Studio, my local script does not work at all. Sometimes it will work perfectly and load everything in while other times nothing will happen. Nothing is printed at all in the output. There is more but this is probably all that matters.

local replicatedStorage = game:GetService("ReplicatedStorage")
local inputService = game:GetService("UserInputService")

local Icon = require(replicatedStorage:WaitForChild("ModuleScripts").Icon)
local parkour = require(replicatedStorage:WaitForChild("ModuleScripts").Parkour)
local battlegrounds = require(replicatedStorage:WaitForChild("ModuleScripts").BattlegroundsClient)

local charEvent = replicatedStorage:WaitForChild("RemoteEvents").ChangeCharacterEvent
local punchEvent = replicatedStorage:WaitForChild("RemoteEvents").PunchEvent

local deb = false
local debTime = 0.5

local loadedIn = false

game.Players.PlayerAdded:Connect(function(plr)
    print("fired")
    if not loadedIn then
        print("loaded")
        parkour.init(game.Players.LocalPlayer)
        battlegrounds.init()
    end
end)

game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
    if loadedIn then
        parkour.reset(game.Players.LocalPlayer)
        battlegrounds.reset()
    end
end)
shadow bough
#

wait so what is the point of the functions separately

#

pretty sure you can do this

#
game.Players.PlayerAdded:Connect(function(plr)
    print("fired")
    if not loadedIn then
        print("loaded")
        parkour.init(game.Players.LocalPlayer)
        battlegrounds.init()
    end
    plr.CharacterAdded:Connect(function(char)
      if loadedIn then
          parkour.reset(game.Players.LocalPlayer)
          battlegrounds.reset()
    end
  end)
end) ```
#

also, theres no point of doing game.Players.PlayerAdded

#

you can probably just remove that line of code