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

My script on door activation won't work, help?

script.Parent.Selected:connect(function(mouse) mouse.Button1Down:connect(function() local t=mouse.Target if t==nil then return end if t:FindFirstChild("door") then if game.Players.LocalPlayer:DistanceFromCharacter(t.Position)<10 then t.door.Transparency = 1 end end end) end)

I don't know why it won't open when I click on it still This is on a local script btw

1 answer

most likely because, you want to click it rather than use mouse.Button1 down event. As a result. It becomes harder to think like that

local player = game.Players.LocalPlayer;
local character = player.Character;
local mouse = player:GetMouse();
function onKeyPress(inputObject,gameProcessed)
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
local doorToChar = mouse.Target:FindFirstChild("Door").CFrame = CFrame.new(mouse.Target:FindFirstChild("Door").x-10,mouse.Target:FindFirstChild("Door").y,mouse.Target:FindFirstChild("Door").z)
if(mouse.Target ~=nil and mouse.Target:FindFirstChild("Door") and character.Humanoid.Torso.Postion = = doorToChar) then
mouse.Target.Transparency = 1;
mouse.Target.CanCollide = false;


end--end of main part of if
end--end of click if
end -end of function
game:GetService("UserInputService").InputChanged:connect(onKeyPress)-- an event for buttons on keyboard

I did not test it in studios. Yet this should work, if the case is your Door is called Door.

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