This script only runs sometimes... why might that be?
I've got a script which handles certain RemoteEvents; this is the code at the beginning to connect the events.
02 | game.Workspace.PlayerLeaveArmory.OnServerEvent:connect( function (plr, args) changeLoadout(plr, args [ 1 ] ) end ) |
04 | game.Workspace.PartAnchor.OnServerEvent:connect( function (plr, args) anchorPart(args [ 1 ] , args [ 2 ] ) end ) |
06 | game.Workspace.ModifyLoadout.OnServerEvent:connect( function (plr, args) modify(plr, args [ 1 ] , args [ 2 ] , args [ 3 ] , args [ 4 ] ) end ) |
08 | game.Workspace.SelectLoadout.OnServerEvent:connect( function (plr, args) select (plr, args [ 1 ] , args [ 2 ] ) end ) |
11 | function loadContainsType( load , weapon) |
12 | local type = weapon.WeaponType.Value |
13 | if type = = "Guns" then . . . |
15 | functions referenced above |
The printouts of "Connection" almost never happen, but when they do, then the script works fine. However, sometimes I have to disable and re enable the script from the Server console in order to make it start working.
The script is pasted into game.Workspace and Enabled by a different script 1 second after all of the RemoteEvents are created and put in Workspace; right at the startup of a server.
As said in the question, this script only connects the events sometimes, and I'm not sure what's causing to work/not work. Thoughts?
Here's the script that pastes the other script and enables it:
03 | if game.Workspace:FindFirstChild( "ArmoryEventsSetup" ) = = nil then |
04 | setup = Instance.new( "BoolValue" ) |
05 | setup.Name = "ArmoryEventsSetup" |
06 | setup.Parent = game.Workspace |
09 | game.Players.PlayerAdded:connect( function (player) |
10 | player:WaitForChild( "Backpack" ) |
11 | local event = Instance.new( "RemoteEvent" ) |
12 | event.Parent = player.Backpack |
13 | event.Name = "PlayerEnterArmory" |
14 | script.ArmoryClient:clone().Parent = player.Backpack |
19 | local event = Instance.new( "RemoteEvent" ) |
20 | event.Parent = game.Workspace |
21 | event.Name = "PlayerLeaveArmory" |
23 | local event = Instance.new( "RemoteEvent" ) |
24 | event.Parent = game.Workspace |
25 | event.Name = "PartAnchor" |
27 | local event = Instance.new( "RemoteEvent" ) |
28 | event.Parent = game.Workspace |
29 | event.Name = "ModifyLoadout" |
31 | local event = Instance.new( "RemoteEvent" ) |
32 | event.Parent = game.Workspace |
33 | event.Name = "SelectLoadout" |
35 | script.ArmoryServer:Clone().Parent = game.Workspace |
37 | game.Workspace.ArmoryServer.Disabled = false |