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

How do I make it so that a part turns collide off when you press k?

Asked by 4 years ago

So far I have this script: plr = game.Players.LocalPlayer mouse = plr:GetMouse()

function woosh() if mouse.Target ~= nil then if mouse.Target.CanCollide== false and mouse.Target.Transparency == .5 then mouse.Target.CanCollide= true mouse.Target.Transparency = 0 else mouse.Target.Transparency = .5 mouse.Target.CanCollide = false end end end

mouse.Button1Down:connect(woosh)

How would I make it so that instead of clicking, you hover over the part with your mouse and press k to do this function?

2 answers

Log in to vote
0
Answered by 4 years ago

Easy.

plr = game.Players.LocalPlayer 
mouse = plr:GetMouse()

function woosh() 

if mouse.Target ~= nil then
if mouse.Target.CanCollide== false and mouse.Target.Transparency == .5 then     mouse.Target.CanCollide= true 
mouse.Target.Transparency = 0
else
mouse.Target.Transparency = .5 
mouse.Target.CanCollide = false
end end end

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then 
    woosh()
    end 
end)

Here ya go, should work.

0
Thank you! SwiftBrickMaster 7 — 4y
0
Hey im trying to learn how to script just for future reference, if I wanted a certain function to happen when I press something thats not a letter such as ctrl or shift, would I just change Enum.Keycode.R to Enum.Keycode.LeftShift? SwiftBrickMaster 7 — 4y
0
Yeah, when you type Enum.Keycode all the other keys should show in the autofill wildmanx20 35 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

The way wild man is doing it is only on the client's side, so I changed his a little bit. Add a local script in StarterGui. In it add this code :

plr = game.Players.LocalPlayer 
mouse = plr:GetMouse()

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if not gameProcessedEvent then
        if inputObject.KeyCode == Enum.KeyCode.K then 
            workspace.CollisionOff:FireServer(mouse.Target)
            if mouse.Target:IsA("BasePart") then
                mouse.Target.CanCollide = false
            elseif mouse.Target:IsA("Model") then
                for i, v in pairs(mouse.Target:GetDescendants()) do
                    if v then
                        if v:IsA("BasePart") then
                            v.CanCollide = false
                        end
                    end
                end
            end
        end
    end 
end)

Then add a remote event in workspace. Call it "CollisionOff" Add this script in it.

script.Parent.OnServerEvent:Connect(function(target)
    if target:IsA("BasePart") then
        target.CanCollide = false
    elseif target:IsA("Model") then
        for i, v in pairs(target:GetDescendants()) do
            if v then
                if v:IsA("BasePart") then
                    v.CanCollide = false
                end
            end
        end
    end
end)
0
This helps too thank you! SwiftBrickMaster 7 — 4y
0
Im glad! BrainDead_Dev 135 — 4y

Answer this question