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

How do I make the script work with specific parts only?

Asked by
VVaffly -3
6 years ago

I need to make it so that it will only work if it has a specific name.

local player = game.Players.LocalPlayer
player.CharacterAdded:wait()
local character = player.Character
local torso = character:WaitForChild("Torso")
local mouse = player:GetMouse()
local humanoid = character:WaitForChild("Humanoid")

local lastwall = nil
mouse.KeyDown:connect(function(key)
    if string.byte(key) == 48 then
    local ray = Ray.new(
        torso.CFrame.p, torso.CFrame.lookVector * 3
    )
    local hit, position, normal = workspace:FindPartOnRay(ray, character)

if hit then
    if hit ~= lastwall then
        local velo = Instance.new("BodyVelocity",torso)
        velo.MaxForce = Vector3.new(300000,300000,300000)
        velo.Velocity =  -torso.CFrame.lookVector*40 + Vector3.new(0,50,0)
        game.Debris:AddItem(velo,0.1)
        lastwall = hit
        wait(.5)
        lastwall = nil
        end
    end
end
end)

2 answers

Log in to vote
0
Answered by 6 years ago

If you're using raycasting, then it should be pretty easy

if(hit.Name == "Whatever name is required") then
    --do the thing
end
Ad
Log in to vote
0
Answered by 6 years ago

So if I was doing this with a lot of parts, and needed one of the same name, I would do something like this.

for i,v in pairs(parts parent:GetChildren()) do
    if v.Name == "PartName" then
        -- yes
    end
end

If you wanted to do anything with the part, use v instead of the route.

Answer this question