Sticky note placement isn't working

I want to be able to script a sticky note placement system where you can equip a sticky note tool and a sticky note that has 0.5 transparency will show up where you hover with your mouse on a bulletin board’s board surface and click to place a note.

I haven’t yet programmed the writing feature yet so people can use a UI to write down what the text for the note will be.

The note is a part that has a surface GUI that has a textlabel.

The bulletin board is a model that has a part called BoardSurface that should be where players can hover over to place their sticky note.

I wrote the script, made the tool, and put the items in the right place but nothing happened. I get 0 errors, and 0 messages. Nothing works but the tool shows up properly at the bottom of the screen.

I tried asking ChatGPT for help scripting because I don’t know how to script the placement part of this system yet as it’s been a while since I scripted in Roblox Lua.

There aren’t any YouTube tutorials for this idea and there aren’t any tutorials on devforum otherwise I wouldn’t have asked for help if there was already a post like mine.

Here’s what my explorer looks like:

Here’s my code for the local script:

-- StickyNote Tool Script

local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local replicatedStorage = game:GetService("ReplicatedStorage")

local stickyNoteModel = replicatedStorage:WaitForChild("StickyNote")
local ghostStickyNoteModel = replicatedStorage:WaitForChild("GhostStickyNote")

local ghostNote

local function isBoardSurface(target)
	return target and target:IsA("Part") and target.Name == "BoardSurface"
end

local function updateGhostNote(target)
	if not ghostNote then
		ghostNote = ghostStickyNoteModel:Clone()
		ghostNote.Parent = workspace
	end
	ghostNote.CFrame = target.CFrame * CFrame.new(0, 0, 0.1)
	ghostNote.Transparency = 0.5
end

local function removeGhostNote()
	if ghostNote then
		ghostNote:Destroy()
		ghostNote = nil
	end
end

local function placeStickyNote(target)
	if isBoardSurface(target) then
		local newStickyNote = stickyNoteModel:Clone()
		newStickyNote.CFrame = target.CFrame * CFrame.new(0, 0, 0.1)
		newStickyNote.Parent = workspace
		print("Sticky note placed on board surface")
		removeGhostNote()
	else
		print("Target is not a board surface")
	end
end

tool.Equipped:Connect(function()
	print("Tool equipped")
	print("Player: ", player.Name)
	print("Character: ", player.Character and player.Character.Name or "No character")

	if mouse then
		print("Mouse is available")
	else
		print("Mouse is NOT available")
	end

	mouse.Move:Connect(function()
		local target = mouse.Target
		if target then
			print("Mouse target detected: " .. target.Name)
		else
			print("No mouse target detected")
		end

		if target and isBoardSurface(target) then
			updateGhostNote(target)
		else
			removeGhostNote()
		end
	end)

	mouse.Button1Down:Connect(function()
		print("Mouse button clicked")
		local target = mouse.Target
		if target then
			print("Target detected: " .. target.Name)
			placeStickyNote(target)
		else
			print("No target detected")
		end
	end)
end)

tool.Unequipped:Connect(function()
	removeGhostNote()
end)

Please let me know what’s wrong with my script or what I need to add. I really want to finish this project idea so I’d highly appreciate any help.

Putting mouse in tool doesn’t work as far as I know. Do this instead (put it outside of Tool.Equipped, not inside):

tool.Deactivated:Connect(function()
	print("Clicked with tool")
	local target = mouse.Target
	if target then
		print("Target detected: " .. target.Name)
		placeStickyNote(target)
	else
		print("No target detected")
	end
end)

1 Like

Have you checked off RequiresHandle on your tool?
image

1 Like

I checked it off and the script’s print statements are showing up now, however, there is no ghost sticky note being displayed and hovering over the board surface of the bulletin board so it’s effectively doing nothing.

It ended up working even with the mouse inside the function.

Thank you for responding to my post and trying to help, I still appreciate it!

The problem was that I had “RequiresHandle” checked automatically so when I unchecked it and changed my script, it started working.

Thank you for your help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.