Universal Script 📌
3.5k Views
49 Executions

Create Part On Click

Universal Script 📌
greenapple1812
greenapple1812First script
1 year ago
Get an executor
Please login to perform these actions:

Does it work?

No reports yet

No reports yet. Tried it? Be the first to say.

Also noticed:

Description

Creates a black part when you click on something.

View Raw
-- LocalScript in StarterPlayerScripts (Mobile/PC Compatible)
 
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local UIS = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")
 
-- Part constants
local SIZE = Vector3.new(5, 0.5, 5) -- 0.5 studs flat
local BLACK = Color3.new(0, 0, 0)
 
local function onClick(input, GPE)
    -- Check for left click OR touch input, and ensure no UI blocking (GPE)
    local isPrimaryAction = (input.UserInputType == Enum.UserInputType.MouseButton1) or 
    (input.UserInputType == Enum.UserInputType.Touch and input.UserInputState == Enum.UserInputState.Begin)
    
    if isPrimaryAction and not GPE then
        
        -- Check if the mouse/touch is pointing at a physical object (not the sky)
        local target = Mouse.Target
        if target then
            local p = Instance.new("Part")
            p.Size = SIZE
            p.Color = BLACK
            p.Anchored = true
            
            -- Place the part centered on the click spot, offset half its thickness up
            local pos = Mouse.Hit.Position + Vector3.new(0, SIZE.Y / 2, 0)
            p.CFrame = CFrame.new(pos)
            
            p.Parent = Workspace
        end
    end
end
 
UIS.InputBegan:Connect(onClick)



Comments

1
Log in to join the conversation. Login
Odetari's profile picture
Odetari1 year ago

bro ia why is ia the script says local script in staterplayerscript

1

More universal scripts

See all
Script hub
58
3
3 hours ago
Key System

Script hub

NEW Script Hub

Script hub
274
247
18 hours ago
Universal Script 📌
19.4k
178.7k
Bumped 1 hour ago
Key System
Script hub
135
9
3 hours ago
Key System
Script hub
272.4k
143.3k
Bumped 2 hours ago
Key System
Script hub
182.3k
1.8M
Bumped 3 hours ago
Key System

Script hub

#18 this week

Verified script badgeAirflow HUB

Script hub
71.4k
235.0k
Bumped 3 hours ago
Key System
Script hub
269
16
4 hours ago