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

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

Asked by
net_h 13
5 years ago
Edited 5 years ago

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?

0
It's hard to help people with no script posted. This is Scripting Helpers, not script helpers. ghxstlvty 133 — 5y
0
Sorry. I don't really know how to reference to a part to do something when clicked. This is mainly my question. net_h 13 — 5y
0
ill reply in 20 minute if nobody else replies royaltoe 5144 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

Ad

Answer this question