Otiaks2356
(interfield3493)
December 21, 2024, 1:04pm
#1
i want it that if the player leaves it grabs the value
For example, if the player leaves, it should automatically eliminate them but I always get a nil value because the player left is there’s any way to fix it
Players.PlayerRemoving:Connect(function(player)
print(player.Name .. " left")
local roomName = player.RoomName.Value
print(roomName)
ReplicatedStorage.MultiplayerStats.PlayersDied.Value = ReplicatedStorage.MultiplayerStats.PlayersDied.Value + 1
Dormitory.Room[roomName].Owner.Value = ""
player.Eliminated.Value = true
end)
Is it a local or server script? Do both roomName and player.Name … " left" print()
in the output?
You haven’t provided any context into which value is nil
here. Can you shed some light?
Otiaks2356
(interfield3493)
December 21, 2024, 1:31pm
#4
the script is from the serverscript in the serverscriptservice
Otiaks2356
(interfield3493)
December 21, 2024, 1:31pm
#5
Players.PlayerRemoving:Connect(function(player)
print(player.Name .. " left")
local roomName = player.RoomName.Value
print(roomName)
ReplicatedStorage.MultiplayerStats.PlayersDied.Value = ReplicatedStorage.MultiplayerStats.PlayersDied.Value + 1
Dormitory.Room[roomName].Owner.Value = ""
player.Eliminated.Value = true
end)
updated script.
What does the output say, when you hit play?
Otiaks2356
(interfield3493)
December 21, 2024, 1:36pm
#7
I got “[playername] left”
espically for my username, “Otiaks2356 left”
Set roomName to nil
on top of: local roomName = player.RoomName.Value:
local roomName = nil
local roomName = player.RoomName.Value
Otiaks2356
(interfield3493)
December 21, 2024, 1:47pm
#9
Otiaks2356 left - Server - GameHandler:82
08:47:28.451 - Server - GameHandler:85
08:47:28.451 Room is not a valid member of Folder "Workspace.Dormitory"
Please clarify your original error
1 Like
Placewith5s
(Placewith5s)
December 21, 2024, 1:53pm
#11
Edit: What happens now?
-- print everything
Players.PlayerRemoving:Connect(function(player)
print(player.Name .. " left")
print(player.Eliminated.Value)
local roomName = nil
print(roomName)
local roomName = player.RoomName.Value
print(roomName)
ReplicatedStorage.MultiplayerStats.PlayersDied.Value = ReplicatedStorage.MultiplayerStats.PlayersDied.Value + 1
print(ReplicatedStorage.MultiplayerStats.PlayersDied.Value)
Dormitory.Room[roomName].Owner.Value = ""
print(Dormitory.Room[roomName].Owner.Value)
player.Eliminated.Value = true
print(player.Eliminated.Value)
end)
Let’s wait for OP to provide us with the original output. That will be enough to give us a solid start
1 Like
mc7oof
(oof)
December 21, 2024, 1:56pm
#13
roomName will be nil after this point [ local roomName = nil
] in the script above.
Do that last.
1 Like
Otiaks2356
(interfield3493)
December 21, 2024, 1:57pm
#14
08:56:51.185 Otiaks2356 left - Server - GameHandler:82
08:56:51.185 false - Server - GameHandler:83
08:56:51.185 nil - Server - GameHandler:85
08:56:51.185 - Server - GameHandler:87
08:56:51.185 1 - Server - GameHandler:89
08:56:51.185 Room is not a valid member of Folder "Workspace.Dormitory" - Server - GameHandler:90
08:56:51.185 Stack Begin - Studio
08:56:51.185 Script 'ServerScriptService.GameHandler', Line 90 - Studio - GameHandler:90
08:56:51.185 Stack End - Studio
The error is the most important part:
Room is not a valid member of Folder “Workspace.Dormitory”
Focus on determining why that is. roomName
being an empty string is also concerning
1 Like
Otiaks2356
(interfield3493)
December 21, 2024, 2:02pm
#16
I forgot to add the s at the “Room” so "Dormitory.Rooms[roomName].Owner.Value = “” like Room is changed to Rooms
Placewith5s
(Placewith5s)
December 21, 2024, 2:02pm
#17
It does not print anything or true
for player.Eliminated.Value
at the end.
Otiaks2356
(interfield3493)
December 21, 2024, 2:03pm
#18
I keep getting this
09:02:32.284 is not a valid member of Folder "Workspace.Dormitory.Rooms"
That is because an error was raised
Otiaks2356
(interfield3493)
December 21, 2024, 2:03pm
#20
What if I made a folder about players and then add roomnamevalues in?