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)
3 comments
Thank you!
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?
Yeah, when you type Enum.Keycode all the other keys should show in the autofill