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

is there a script for spawning blocks where the player is aiming at if you click a gui button?

so i wanted to make a game called "G-Blox" and i wanted a spawn menu with images that if you click on it spawns a model where the player is aiming at

i am bad at scripting so im sorry if i sound bad or anything

the game link is here: https://www.roblox.com/games/5133689224/G-Blox?refPageId=37ad817c-8b78-46d9-a1d5-2d1868fbd68a

any help will be appreciated alot :D

2 comments

0

I'd use something that gets the mouse position and then on a click it spawns

0

this isnt really specific

1 answer

If you want the Menu to work, you'll have to use UserInputService to open the menu, as there is no possible way to open the menu by clicking it.

Next, if you want to spawn the object on the player's mouse you'll have to use game.Players.LocalPlayer:GetMouse() and set that equal to a variable, and then use Mouse.Hit(.p) or Mouse.Origin and set the objects position/CFrame equal to that.

For the images, you'll have to create those yourself or use Roblox Image Endpoints for pre-existing images.

Do some research on these and your game will work fine.


Examples

UserInputService

game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then --// Checks if the player is typing, opening tab, pressing esc, etc. anything game related basically. If it is game related, it won't fire the event, if it isn't game related, it'll continue through the code.
		if input.KeyCode == Enum.KeyCode.Z then
			print("Pressed Z")
		end
	end
end)

Mouse

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

game:GetService("RunService").RenderStepped:Connect(function()
	print(mouse.Hit.p, mouse.Origin, mouse.Hit)
end

Image Endpoints

Dev Forum


Hope this helped! Feel free to select this as an answer if this helped you!

Do some research, watch some youtube videos, test things with the services and other things and it'll work out eventually!


Documentation + API

1 comment

0

i dont think watching some youtube videos will help since im searching for 3 hours or longer oofios

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