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

How do I make a clickable part that places a part above you?

So I'm watching a LUA scripting tutorial from alvin blox and I had a question because I don't think this was mentioned. But I need to make it so if player clicks on PART then a new PART will spawn five studs above them. How is that possible?

3 comments

0

It's hard to help people with no script posted. This is Scripting Helpers, not script helpers.

0

Sorry. I don't really know how to reference to a part to do something when clicked. This is mainly my question.

0

ill reply in 20 minute if nobody else replies

1 answer

The first thing you would need to do is make it so a script can detect a clickable part. You can do this by adding a ClickDetector into the part.

local part = script.Parent 

-- Create a new click detector 
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = part 
ClickDetector.MaxActivationDistance = 10 -- Max distance a player can click the part

-- Set up the click function so our part can listen for clicks 
ClickDetector.MouseClick:Connect(function(playerWhoClicked) 
	local newPart = Instance.new("Part")
	newPart.Name = "SpawnPart"
	newPart.Anchored= true
	newPart.Parent = workspace
	
	-- Get the character from the playerWhoClicked parameter  
	local characterWhoClicker = playerWhoClicked.Character
	local head = characterWhoClicker.Head

	-- Position the new part to the same position as the head plus 5 studs in the Y direction
	newPart.CFrame = head.CFrame + Vector3.new(0, 5, 0)
end)

Source

Edit: Link

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