I want to create a game like ‘Retail Tycoon 2’, So i want to deplace the part at the mouse Position.
Thanks you so much!
I want to create a game like ‘Retail Tycoon 2’, So i want to deplace the part at the mouse Position.
Thanks you so much!
local player = game:GetService('Players').LocalPlayer
repeat wait() until player.Character
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
print(mouse.Hit.p)
end)
Might work:
Player = game.Players.LocalPlayer;
Mouse = Player:GetMouse();
IsMoving = nil;
Activated = false;
wait()
Mouse.Button1Down:Connect(function()
if Activated == false then
Activated = true IsMoving = true
print(Mouse.Hit.Position)
elseif Activated == true then
Activated = false IsMoving = nil
end
end)
if Activated == true then
repeat wait()
print("Moving")
until Activated == false
end
If you want to know the mouse position on the client, you can do this:
local mouse = game.Players.LocalPlayer:GetMouse()
print(mouse.Hit) --> CFrame in the Workspace
print(mouse.Target) --> Object mouse is pointing at (can be nil)
If you want the server to know your mouse position, it all depends on RemotesEvents or RemoteFunctions.
For your case, the server doesn’t really need to know your mouse position, up until you click to place a structure in your tycoon.
Your structure placement localscript should look something like this:
--\\ Client Structure Handler
local uis = game:GetService("UserInputService")
local mouse = game.Players.LocalPlayer:GetMouse()
local orientation = Vector3.new(0,0,0)
local selectedstructure = "CashRegister" -- handle this variable yourself!
--\\ User Input
uis.InputBegan:Connect(function(input, process)
if not process then return end
--\\ Mouse Click
if input.UserInputType == Enum.UserInputType.Mouse then
local position = mouse.Position
-- make a remotes folder, and a remote called PlaceStructure!
game.ReplicatedStorage.Remotes.PlaceStructure:FireServer(selectedstructure, position, orientation)
end
--\\ Structure Rotation
-- If your holding Control, it only rotates 45 degrees. Or else it's 90.
if input.KeyCode == Enum.KeyCode.R then
orientation += Vector3.new(0,
uis:IsKeyDown(Enum.KeyCode.LeftCtrl) and 45 or 90
,0)
-- update blueprint structure orientaiton here
end
end)
uis.InputChanged:Connect(function(input, process)
if not process then return end
if input.UserInputType == Enum.UserInputType.Mouse then
-- handle grid placement system here
end
end)
And the server handler for structures should start like this:
--\\ Server Structure Handler
game.ReplicatedStorage.PlaceStructure.OnServerEvent:Connect(function(player, structure, position, orientation)
if type(structure) ~= "string" then return end
if type(position) ~= "Vector3" then return end
if type(orientation) ~= "Vector3" then return end
-- handle structure placing here
end
That’s really all I can provide since I can’t make a tycoon over the Devforum!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.