Add globals to fix join corescript

This commit is contained in:
Lewin Kelly 2023-04-26 14:50:36 +01:00
parent e704d69398
commit 0dae41c621
2 changed files with 14 additions and 23 deletions

View File

@ -71,9 +71,8 @@ pcall(function()
settings().Network.MtuOverride = 1400 settings().Network.MtuOverride = 1400
end end
end) end)
local client = game:GetService("NetworkClient") client = game:GetService("NetworkClient")
local visit = game:GetService("Visit") visit = game:GetService("Visit")
local setMessage
setMessage = function(message) setMessage = function(message)
return game:SetMessage((function() return game:SetMessage((function()
if not false then if not false then
@ -83,11 +82,9 @@ setMessage = function(message)
end end
end)()) end)())
end end
local showErrorWindow
showErrorWindow = function(message, _, _) showErrorWindow = function(message, _, _)
return game:SetMessage(message) return game:SetMessage(message)
end end
local reportError
reportError = function(err, message) reportError = function(err, message)
print("***ERROR*** " .. tostring(err)) print("***ERROR*** " .. tostring(err))
if not test then if not test then
@ -97,7 +94,6 @@ reportError = function(err, message)
wait(4) wait(4)
return showErrorWindow("Error: " .. tostring(err), message, "Other") return showErrorWindow("Error: " .. tostring(err), message, "Other")
end end
local onDisconnection
onDisconnection = function(_, lostConnection) onDisconnection = function(_, lostConnection)
if lostConnection then if lostConnection then
return showErrorWindow("You have lost the connection to the game", "LostConnection", "LostConnection") return showErrorWindow("You have lost the connection to the game", "LostConnection", "LostConnection")
@ -105,7 +101,6 @@ onDisconnection = function(_, lostConnection)
return showErrorWindow("This game has shut down", "Kick", "Kick") return showErrorWindow("This game has shut down", "Kick", "Kick")
end end
end end
local requestCharacter
requestCharacter = function(replicator) requestCharacter = function(replicator)
local connection local connection
connection = player.Changed:connect(function(property) connection = player.Changed:connect(function(property)
@ -127,7 +122,6 @@ requestCharacter = function(replicator)
return return
end end
end end
local onConnectionAccepted
onConnectionAccepted = function(url, replicator) onConnectionAccepted = function(url, replicator)
local connectResolved = true local connectResolved = true
local waitingForMarker = true local waitingForMarker = true
@ -157,17 +151,14 @@ onConnectionAccepted = function(url, replicator)
wait(0.5) wait(0.5)
end end
end end
local onConnectionFailed
onConnectionFailed = function(_, err) onConnectionFailed = function(_, err)
return showErrorWindow("Failed to connect to the Game. (ID=" .. tostring(err) .. ")", "ID" .. tostring(err), "Other") return showErrorWindow("Failed to connect to the Game. (ID=" .. tostring(err) .. ")", "ID" .. tostring(err), "Other")
end end
local onConnectionRejected
onConnectionRejected = function() onConnectionRejected = function()
connectionFailed:disconnect() connectionFailed:disconnect()
return showErrorWindow("This game is not available. Please try another", "WrongVersion", "WrongVersion") return showErrorWindow("This game is not available. Please try another", "WrongVersion", "WrongVersion")
end end
local idled = false local idled = false
local onPlayerIdled
onPlayerIdled = function(time) onPlayerIdled = function(time)
if time > 20 * 60 then if time > 20 * 60 then
showErrorWindow(string.format("You were disconnected for being idle %d minutes", time / 60), "Idle", "Idle") showErrorWindow(string.format("You were disconnected for being idle %d minutes", time / 60), "Idle", "Idle")

View File

@ -4,7 +4,7 @@ import "macros" as { $ }
-- onPlayerAdded = (player) -> -- onPlayerAdded = (player) ->
-- -- override -- -- override
$lua "-- MultiplayerSharedScript.lua inserted here ------ Prepended to Join.lua --" $lua[[-- MultiplayerSharedScript.lua inserted here ------ Prepended to Join.lua --]]
try try
game\SetPlaceID _PLACE_ID, false game\SetPlaceID _PLACE_ID, false
@ -80,11 +80,11 @@ try
-- globals ----------------------------------------- -- globals -----------------------------------------
client = game\GetService "NetworkClient" global client = game\GetService "NetworkClient"
visit = game\GetService "Visit" global visit = game\GetService "Visit"
-- functions --------------------------------------- -- functions ---------------------------------------
setMessage = (message) -> global setMessage = (message) ->
-- todo: animated "..." -- todo: animated "..."
game\SetMessage if not false game\SetMessage if not false
message message
@ -93,11 +93,11 @@ setMessage = (message) ->
"Teleporting ..." "Teleporting ..."
showErrorWindow = (message, _, _) -> global showErrorWindow = (message, _, _) ->
game\SetMessage message game\SetMessage message
reportError = (err, message) -> global reportError = (err, message) ->
print "***ERROR*** #{err}" print "***ERROR*** #{err}"
if not test if not test
visit\SetUploadUrl "" visit\SetUploadUrl ""
@ -108,14 +108,14 @@ reportError = (err, message) ->
-- called when the client connection closes -- called when the client connection closes
onDisconnection = (_, lostConnection) -> global onDisconnection = (_, lostConnection) ->
if lostConnection if lostConnection
showErrorWindow "You have lost the connection to the game", "LostConnection", "LostConnection" showErrorWindow "You have lost the connection to the game", "LostConnection", "LostConnection"
else else
showErrorWindow "This game has shut down", "Kick", "Kick" showErrorWindow "This game has shut down", "Kick", "Kick"
requestCharacter = (replicator) -> global requestCharacter = (replicator) ->
-- prepare code for when the Character appears -- prepare code for when the Character appears
local connection local connection
connection = player.Changed\connect (property) -> connection = player.Changed\connect (property) ->
@ -139,7 +139,7 @@ requestCharacter = (replicator) ->
-- called when the client connection is established -- called when the client connection is established
onConnectionAccepted = (url, replicator) -> global onConnectionAccepted = (url, replicator) ->
connectResolved = true connectResolved = true
waitingForMarker = true waitingForMarker = true
@ -178,18 +178,18 @@ onConnectionAccepted = (url, replicator) ->
-- called when the client connection fails -- called when the client connection fails
onConnectionFailed = (_, err) -> global onConnectionFailed = (_, err) ->
showErrorWindow "Failed to connect to the Game. (ID=#{err})", "ID#{err}", "Other" showErrorWindow "Failed to connect to the Game. (ID=#{err})", "ID#{err}", "Other"
-- called when the client connection is rejected -- called when the client connection is rejected
onConnectionRejected = -> global onConnectionRejected = ->
connectionFailed\disconnect! connectionFailed\disconnect!
showErrorWindow "This game is not available. Please try another", "WrongVersion", "WrongVersion" showErrorWindow "This game is not available. Please try another", "WrongVersion", "WrongVersion"
idled = false idled = false
onPlayerIdled = (time) -> global onPlayerIdled = (time) ->
if time > 20 * 60 if time > 20 * 60
showErrorWindow string.format("You were disconnected for being idle %d minutes", time / 60), "Idle", "Idle" showErrorWindow string.format("You were disconnected for being idle %d minutes", time / 60), "Idle", "Idle"
client\disconnect! client\disconnect!