ServerScriptService.Main:6: attempt to index nil with 'Clone'

no it doesnt gives an error i guess

so i have this line of code:

print(game.ReplicatedStorage.Maps:FindFirstChild(winner))

and it prints out a nil

i changed my script and it says that voting.MapVoting() is nil even when vote is ended

just make that print(winner)
and maybe add a print(mapVotes)

image

So can you return winner.name and then use that to find the map on the server script and then make the clone?

i cant find the map on the server script and make the clone

Alright, so here’s the things you’ve told us that are actually crucial to the problem you’re having:

  • Your Main Script is within the ServerScriptService.
  • Your maps are within the ReplicatedStorage.
  • You’re trying to clone a map into the workspace that resides in the ReplicatedStorage.

So, this actually should tell us what the problem is. You heard of the ServerStorage, right? You would want to put your maps in there if they’re not going to be used by the client. The reason why is because, apparently (in strict wording from the documentation),

Scripts running in ServerScriptService may need access to various other assets which are not scripting-related, such as prefabricated models to be cloned. Such assets should go in ServerStorage.

Source: ServerScriptService | Roblox Creator Documentation

So if you’re not going to use the maps on the client side, (which, why would you do that? and it doesn’t seem like you are), put those maps in ServerStorage so that the script can access it. Otherwise, your script should run as expected. Hope this helps!

2 Likes

The big issue that I see is that you are handing all processing within the event handler. While you can do this, it’s causing an architectural problem When the event handler exits, where does the return go to? Nowhere.

What you want to do is define your winner outside any function so it’s in the global script context. Then you use the event handler to manipulate it per your events. When the timer runs out, then check the list to see which map won the vote.

So i fixed my problem thanks to people that tried to help me

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.