Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Teleporting Players, Cloning Nascars, Game starting on 2 players. Help please?

Asked by 9 years ago

Alright so here's the delima. I have to create a model for each player that joins, and the problem with this is if a player joins and leaves, then it will need to destroy itself. Alright so here's what I'm creating a basic classic version of nascar. I need to know how to teleport eachother to a model, that's created specifically for them. I believe I could use values stored inside of ServerStorage, but I wouldn't know how. This is what I need help with:

each player teleports to their own nascar if a player leaves it destroys their nascar from ServerStorage game starts on 2 players

Using the PlayerAdded event is alittle tricky. I don't know how I'd do this explain please

Player  =  game.Players.LocalPlayer
Player.PlayerAdded:connect(function()
print("This is the part where it'd copy the model")
game.ServerStorage.Nascar:Clone()
Nascar.Parent = game.Lighting
end)

Alright so in here if it copies it, it'd have to need a value inside of it that says like 1,2,3,4 or anything. So each player that joins has their own number so the script doesn't glitch and delete all players. I believe the cars would be stored inside of "Nascars", as a model. And it'd look inside of the script for each car to clone it into workspace right when the game starts.

** This is an event so the tag is necessary **

1 answer

Log in to vote
-1
Answered by 9 years ago

1st you don't use local player to connect a function. You would, I believe, only use game.Players for PlayerAdded. So it starts as this.

game.Players.PlayerAdded:connect(function( p ) --The p in parentheses represents the player

end)

Then you take the "Nascar" model from the Server Storage. The way you put it, you forgot to name the clone a variable to add it to workspace. You also wanted 2 players to start. So it would look like this.

game.Players.PlayerAdded:connect(function( p ) --The p in parentheses represents the player
    players=game.Players:GetPlayers()
    if #players >= 2 then --Check if there are more than 2 people in the table players created in the last line
        for i=1,#players do
            if string.sub(workspace["Nascar"].Name,7)~=players[i].userId then
                local car=game.ServerStorage["Nascar"]:Clone()
                car.Parent=workspace
                car.Name=car.Name .. players[i].userId
            end
        end
    end
end)

So it should wait for 2 people, then when there is, clones the amount of cars needed to make it equal. Also to make it identify who has a car it adds their userId to the end of the car name. Now if a player leaves there car is there still.

game.Players.PlayerAdded:connect(function( p ) --The p in parentheses represents the player
    players=game.Players:GetPlayers()
    if #players >= 2 then --Check if there are more than 2 people in the table players created in the last line
        for i=1,#players do
            if string.sub(workspace["Nascar"].Name,7)~=players[i].userId then
                local car=game.ServerStorage["Nascar"]:Clone()
                car.Parent=workspace
                car.Name=car.Name .. players[i].userId
            end
        end
    end
end)

game.Players.PlayerRemoving:connect(function( p )
    if workspace["Nascar" .. p.userId] then
        workspace["Nascar" .. p.userId]:Destroy()
    end
end)

I am not totally certain that it will find the userId, but it's worth a shot

MAKE SURE THIS IS REGULAR SCRIPT

0
'string.sub(workspace["Nascar"],7)' - An instance can't be used as an argument for string.sub method. Goulstem 8144 — 9y
0
@Goulstem string.sub(workspace["Nascar"].Name,7) - There XtremeSpy 80 — 9y
Ad

Answer this question