I have this script in ServerScriptService:
01 | game.Players.PlayerAdded:Connect( function (player) |
02 | local cframeStored |
03 |
04 | player.CharacterAdded:Connect( function (character) |
05 | local player = game.Players.LocalPlayer |
06 |
07 | character:WaitForChild( "Humanoid" ).Died:Connect( function () |
08 |
09 | if player.Team = = "Prisoner" then |
10 | cframeStored = CFrame.new(game.Workspace.Prisoner.Position + Vector 3. new( 0 , 10 , 0 )) |
11 | end |
12 | end ) |
13 | end ) |
14 | end ) |
Whenever I play my game, Roblox outputs with this error message:
ServerScriptService.TeamSpawnLocation:9: attempt to index local 'player' (a nil value)
How do I fix this problem?
Any help is appreciated :)
The problem is that you are having local player in a server script instead use the parameter of the player added
Server Script:
01 | game.Players.PlayerAdded:Connect( function (player) -- The player is given here |
02 | local CFrameStored |
03 |
04 | player. CharacterAdded:Connect( function (character) |
05 | character:WaitForChild( "Humanoid" ).Died:Connect( function () |
06 | if player.Team.Name = = "Prisoner" then |
07 | local CFrameStored = CFrame.new(game.Workspace.Prisoner.Position + Vector 3. new( 0 , 10 , 0 )) |
08 | end ) |
09 | end ) |
10 | end ) |
11 | end ) |
If you see any mistakes it's because I'm on mobile