Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make so the model will follow once in clicked the GUI?

Asked by 4 years ago
Edited 4 years ago

i am a newbie at scripting but i know how to script.I am making a Tycoon Building game I have a problem where i want to make the model follow my mouse cursor once i clicked the GUI button, and i want it continuously follow the cursor once i click it

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03local function round (n)
04    return math.floor(n + 0.5)
05end
06 
07if game.StarterGui.ScreenGui.BuildModeFrame.BuildSelections.IronWall
08    then
09        game:GetService("UserInputService").InputChanged:Connect(function(input, gameProcessed)
10            game.Workspace.walls.ironwall:SetPrimaryPartCFrame(CFrame.new(round(mouse.Hit.Position.X),round(mouse.Hit.Position.Y),round(mouse.Hit.Position.Z)) + Vector3.new(0,5,0))
11    end)
12end

some parts of this code isn't necessarily needed to be there. Please help and also if you can make this script more shorter that would help a lot , thank you in advance

1 answer

Log in to vote
0
Answered by
blowup999 659 Moderation Voter
4 years ago
Edited 4 years ago

I haven't looked into this myself, but with Miners Haven opensource, I'm sure it's there somewhere. Also worth checking out: https://scriptinghelpers.org/blog/creating-a-furniture-placement-system

For the actual question though, the way I always handle these things is I have a function that I BindToRenderStep with RunService.

In the function, I'll have everything that needs to run every frame such as:

1if isPlacingObject then
2    setObjectPosition()
3end

Then when the gui is clicked, I set isPlacingObject to true, and clone the object and the RunService function will automatically set it for you

0
This is helpful but I still don't understand how to make it work though spectacularnicknack 2 — 4y
0
What I'm trying to say is like a menu system with some selection of items , where if you choose it would generate a 3D blueprint spectacularnicknack 2 — 4y
Ad

Answer this question