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?
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)
Edit: Link