adithegman Posted February 7, 2019 Share Posted February 7, 2019 I'm trying to develop the spectating system and ran into this error: When a player dies and the startSpectate event is called from server, there is an error at the setCameraTarget function: bad argument @ 'setCameraTarget' [ Expected Vector 3 at argument 1, got nil] I checked the updatePlayers() function to see whether the players table was formed correctly or not and it is. Thanks for helping! Client script: local players = {} local index = 1 local function updatePlayers() players = {} local candidates = getElementsByType("player") for k, v in ipairs(candidates) do if getElementData(v, "game.status") == "playing" then table.insert(players, v) end end end local function spectatePrevious() if index == 1 then index = #players else index = index - 1 end setCameraTarget(players[i]) end local function spectateNext() if index == #players then index = 1 else index = index + 1 end setCameraTarget(players[i]) end local function startSpectateHandler() setElementData(localPlayer, "game.status", "spectating") updatePlayers() index = 1 bindKey("arrow_l", "down", spectatePrevious) bindKey("arrow_r", "down", spectateNext) t = players[i] setCameraTarget(t) --- This is the line warning the error occurs end local function stopSpectateHandler() unbindKey("arrow_l", "down", spectatePrevious) unbindKey("arrow_r", "down", spectateNext) setCameraTarget(localPlayer) end addEventHandler("onClientResourceStart", resourceRoot, updatePlayers) addEventHandler("onPlayerJoin", root, updatePlayers) addEventHandler("onPlayerQuit", root, updatePlayers) addEvent("startSpectate", true) addEventHandler("startSpectate", localPlayer, startSpectateHandler) addEvent("stopSpectate", true) addEventHandler("stopSpectate", localPlayer, startSpectateHandler) Link to comment
adithegman Posted February 7, 2019 Author Share Posted February 7, 2019 Found error, fixed. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now