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

Car not getting placed in workspace?

When I click a textbutton, I want "Koenigsegg One:1" to clone into workspace and hover over the player that click the button head, it does not clone though.

script.Parent.MouseButton1Click:connect(function()
	game.Players.PlayerAdded:connect(function(plr)
		plr.CharacterAdded:connect(function(char)
			local C = game.ReplicatedStorage.Cars:WaitForChild("Koenigsegg One:1"):Clone()
			C.Parent = game.Workspace
			C:MoveTo(char.HumanoidRootPart.Position + Vector3.new(3, 0, 3))
		end)
	end)
end)

Thanks if you help me :)

3 comments

0

PlayerAdded doesn't work in a localscript.

0

This is a normal script though

0

It doesn't clone because you never actually clone it. You just connect the events (Player- and CharacterAdded). But you don't need the events, just get rid of them. And you should ALWAYS use a LocalScript when working with GUIs.

2 answers

✓ Accepted answer

This is a GUI, you use localscripts for GUIs. Make your script a local script then use the script bellow, under the script is the explanation.

local plr = game.Players.LocalPlayer
repeat wait() until plr.Character -- wait for player to not be nil, then make the variable of it bellow
local char = plr.Character

script.Parent.MouseButton1Click:connect(function()
         local C = game.ReplicatedStorage.Cars:WaitForChild("Koenigsegg One:1"):Clone()
         C.Parent = game.Workspace
         C:MoveTo(char.HumanoidRootPart.Position + Vector3.new(3, 0, 3))
end)

You were using Events in an event in an event, two of which (PlayerAdded/CharacterAdded) wouldn't fire just because you press the button. I'm not even sure what would happen. Comment any questions if you need further explanations or errors occur!

1 comment

0

The car is anchored when it is not suppose to be.

Using localscripts would speed up things..

1 comment

0

Suggestions should be comments

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