Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

3 comments

0

Thank you!

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?

0

Yeah, when you type Enum.Keycode all the other keys should show in the autofill

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)

2 comments

0

This helps too thank you!

0

Im glad!

This discussion is preserved as it was. New answers, comments, and votes are closed.