Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Part won't stay in car even though code?

Ok so I have a car crash game. And after i finally learned how to respawn a car with it not breaking, I tried to add the hitpart and it would still break. So i thought to drive it around and check if it would break and it wouldn't but i wouldn't see it appear it workspace or in under the vehicle. So i did some print bug checking seeing in fact it did spawn in and under the van. But now i just need a way to find out how to make it weld or something to the van since that's what i do with it to the other cars.

Code:

local van = game.ServerStorage.RespawnVan local JustSpawned = false local CHitPart = game.ServerStorage.HitPart

function summon() if script.Parent.MouseClick then local clone = van:Clone() clone.Parent = game.Workspace game.Workspace.RespawnVan:MakeJoints() JustSpawned = true wait(5) JustSpawned = false --Im testing this stuff-- wait(20) local clone2 = CHitPart:Clone() clone2.Parent = game.Workspace.RespawnVan print("HitPart has spawned!") print(clone2.Parent) script.Parent.Script.Disabled = false end end

script.Parent.MouseClick:Connect(summon)``

Just want to know if i can code it or not.

1 comment

2

Put your code into a code block please.

1 answer

Hi! So After looking at your code I notice that you don't have anything welding your new CHitPart to the van that you have summoned. That may be why the "Part won't stay in car even though code."

To weld the part in there we can change your code like so:

local van = game.ServerStorage.RespawnVan
local JustSpawned = false
local CHitPart = game.ServerStorage.HitPart

function summon()
	if script.Parent.MouseClick then
		local clone = van:Clone()
		clone.Parent = game.Workspace
		game.Workspace.RespawnVan:MakeJoints()
		JustSpawned = true
		wait(5)
		JustSpawned = false
		--Im testing this stuff--
		wait(20)
		local clone2 = CHitPart:Clone()
		clone2.CFrame = clone.PrimaryPart.CFrame -- Here is where you move the part

		local weld = Instance.new("WeldConstraint")
		weld.Part0 = clone2
		--You can change weld.Part1 if you don't have a PrimaryPart
		weld.Part1 = clone.PrimaryPart 
		weld.Parent = clone2

		clone2.Parent = game.Workspace.RespawnVan
		print("HitPart has spawned!")
		print(clone2.Parent)
		script.Parent.Script.Disabled = false
	end
end

script.Parent.MouseClick:Connect(summon)

Hopefully this fixes your problem!

3 comments

0

Sorry for such a late response, However, this doesn't work. This code does add the part however with the primary part it just breaks the car since it goes into the middle and not the front. And i changed it like you said to the front bumper and it spawns underneath it, if there is way to make it weild to a specific surface/side, I need to know how to fix this problem.

0

Sorry I forgot to add the part where you move the HitPart onto the car. I have edited my code to reflect that.

0

You can change where you want the part to be by setting its CFrame to where you want it. You don't have to use the PrimaryPart, you can use any part of your car. You don't even have to reference a part's CFrame, you can set your own CFrame if you would like.

This discussion is preserved as it was. New answers, comments, and votes are closed.