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

Please help me with this random select code.

Asked by 10 years ago

When I click on something, I want a kart to appear. So, when I click it, it clones the kart from lighting (clones the kart from inside a model called Karts), and then appears in the game. It will do it the first time, but it doesn't clone it. There is also a script inside the kart seat so that when a player jumps out of it, it disappears. I don't know if that's messing up the teleport with the kart, but it shouldn't be. I don't know what line of code I should edit.

Clicked = script.Parent
BackUpButton = game.Debris.Button
BackUpTextThing = game.Debris.GenerateKart

function onMouseClick(Player)
game.Workspace.Button:remove()
game.Workspace.GenerateKart:remove()
wait(0.1)
m = game.Lighting.GoKarts:GetChildren()
mg = m[math.random(1,#m)]
wait(1)
mg.Parent = game.Debris
wait(1)
mg.Parent = game.Workspace 
mg:makeJoints() 
wait(10)
BackUpButton:clone().Parent = game.Workspace
BackUpTextThing:clone().Parent = game.Workspace
end
Clicked.MouseClick:connect(onMouseClick)

Here is the coding for the script inside the seat:

local car = script.Parent.Parent

script.Parent.ChildAdded:connect(function(o)
if o.Name == "SeatWeld" then
car.Parent = game.Workspace
end
end)

script.Parent.ChildRemoved:connect(function(o)
if o.Name == "SeatWeld" then
wait(1)
car:remove()
end
end)

2 answers

Log in to vote
0
Answered by 10 years ago

I am not sure how to completely solve your problem as I am not familiar with Debris, but I suggest that instead of using Lighting, you should use ServerStorage. Also remove the Lighting tag, as it does not have anything to do with dynamic lighting or the properties of Lighting.

Ad
Log in to vote
1
Answered by
AxeOfMen 434 Moderation Voter
10 years ago

The Debris service is used to automatically remove parts from your workspace after a short time. Do not store parts or models in the Debris service if you intend to continue using them. Instead, store your items in the ServerStorage service...

Clicked = script.Parent
BackUpButton = game.ServerStorage.Button
BackUpTextThing = game.ServerStorage.GenerateKart

function onMouseClick(Player)
    game.Workspace.Button:Destroy()
    game.Workspace.GenerateKart:Destroy()
    wait(0.1)
    m = game.ServerStorage.GoKarts:GetChildren()    
    mg = gm[math.random(#m)]
    wait(1)
    mg.Parent = game.Workspace 
    mg:makeJoints()
    wait(10)
    BackUpButton:clone().Parent = game.Workspace
    BackUpTextThing:clone().Parent = game.Workspace
end
Clicked.MouseClick:connect(onMouseClick)
0
Well, the button is destroy and so is the script, but I have a backup button that is in ServerStorage. johnjohncar 10 — 10y

Answer this question