Currently I’m trying to script a button to open and close whichever wall object it is attached to. The idea is that you press the button, the wall goes up. Press it again, the wall goes down. This behaviour does work, however this is with the caveat that once the player is within a certain distance of the wall, it will just start to follow the player. This only happens once the wall has been activated, and once the player leaves this range, the wall no longer attempts to follow the player. I have truly no idea why it is doing this.
Interact.Button in InteractibleFuncs ModuleScript
function Interact.Button(Object) -- Handles button de/activation
local Target = Object:FindFirstChildOfClass("ObjectValue").Value
local Activated = Target:FindFirstChildOfClass("BoolValue") -- Indicates activation state
if Target.Name == "Wall" then
if Activated.Value then -- Lowers wall
Target:TranslateBy(Vector3.new(0, -10, 0))
Activated.Value = false
else -- Raises wall
Target:TranslateBy(Vector3.new(0, 10, 0))
Activated.Value = true
end
end
end
Button Interfacing in InteractionController LocalScript
local Global = require(script.Parent.GlobalFuncs)
local Interact = require(script.Parent.InteractibleFuncs)
Global.Mouse.Button1Down:Connect(function()
local Cast = Global.CastToMouse()
local CastInstance = Cast.Instance
local CastPosition = Cast.Position
local Ancestor = CastInstance:FindFirstAncestor("Interactibles")
--[[
The folder structure is as so: Workspace -> Environment -> Interactibles
The wall Model is in the Environment folder, the button is in the Interactibles folder
--]]
if Ancestor then
local Target = CastInstance:FindFirstAncestorOfClass("Model")
local TargetPivot = Target:GetPivot()
local TargetPosition = Vector3.new(TargetPivot.X, TargetPivot.Y, TargetPivot.Z)
local LookVector = CFrame.lookAt(Cast.Position, Global.Root.Position)
Global.Task = Target -- This variable just tells the game which item was clicked on
Global.MoveTo(TargetPosition + LookVector.LookVector.Unit * 6, false)
if Target.Name == "Button" then
Interact.Button(Target)
end
return
end
Global.Task = nil
Global.TapTarget.Position = CastPosition
Global.MoveTo(CastPosition, true)
end)
I’ve used multiple different methods of changing the position of the wall (which to be clear is a Model), including TranslateBy, MoveTo, and and PivotTo. All of them result in the same thing. The button and the object are not directly interfaced with anywhere else in my scripts. I’m not sure if its something I overlooked as a consequence of my inexperience or if something has just gone horribly wrong, but if anyone might know what’s going on I would be so grateful!