Placement System Toggle

Hello there!
I found this helpful topic on making a placement system, and it helps a lot. The thing I want to know, though, is how I can script a textbutton screen Gui to toggle placement mode on and off for the player.

I would appreciate any and all help! Thanks!

2 Likes

I haven’t read the program you linked in details, but it seems like there’s a RunService.RenderStepped connection set up to update the preview model every frame. It appears to use ContextActionService to bind actions related to the placement system to user inputs.

To “toggle it on/off”, you’d have to disconnect the connections that should only be there when the system is active, and unbind actions that should only be bound when it’s active.

I would wrap that in two functions, called enablePlacementMode and disablePlacementMode. That way, a LocalScript can listen to your TextButton being clicked, and call the appropriate function. You might also want a function called getIsPlacementModeEnabled for this purpose.

1 Like

Thanks. I’m not quite sure how to do that, but I found another way to make it work. I renamed the part where you place things, so it wouldn’t build, and then the button renames it what it originally was. I made another button that renames it, but I can’t click it with the placement mode on, or else it just places a furniture item and won’t activate the button.

1 Like

How are you detecting if the mouse was clicked? If you use UserInputService.InputBegan, the second parameter that’s passed to the listener function is a bool indicating whether or not that input has already been processed, e.g. by a GUI button being clicked, or if the player is typing in chat for keyboard input. E.g.:

UserInputService.InputBegan:Connect(function(inputObject, gameProcessedEvent)
    if gameProcessedEvent then
        print("Event has already been processed, ignoring")
    else
        if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
            onClicked()
        end
    end
end)