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

[FE] How do I get the mouse's position?

local script:

userInputService.InputBegan:connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then
		if inputObject.KeyCode == Enum.KeyCode.Z then
			--if playerData.grimoireType.Value == "fire" then
				if canExecute and canUseExplodingFireBall and playerData.grimoireIsOpen.Value == true then
					canExecute = false
					canUseExplodingFireBall = false
					request.fireGrimoireHandler:FireServer(playerMouse.Hit.p, "explodingFireBall")
					wait(0.75)
					canExecute = true
					wait(4)
					canUseExplodingFireBall = true
				end
			--end
		end
	end
end)

server script:

request.fireGrimoireHandler.OnServerEvent:connect(function(player, mousePosition, spell)
	local playerData = replicatedStorage.dataHolder[player.UserId]
	local character = player.Character
	local root = character.HumanoidRootPart
	if spell == "explodingFireBall" then
		local explodingFireBall = assets.spells.fire.explodingFireBall:Clone()
		explodingFireBall.Name = player.Name .. "'s exploding fire ball!"
		explodingFireBall.Parent = workspace
		weldBetween(explodingFireBall, character["RightHand"], CFrame.new(0, 0.75, 0))
		local bodyVelocity = Instance.new("BodyVelocity", explodingFireBall)
		bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		bodyVelocity.Velocity = (mousePosition - explodingFireBall.Position).unit * 100
		explodingFireBall.partWeld:Destroy()
		game.Debris:AddItem(explodingFireBall, 2)
	end
end)

I need help making it so that instead of getting the mouse's position when pressing the key, I get the mouse's position when I remove the weld. Or something along those lines.

bodyVelocity.Velocity = (mousePosition - explodingFireBall.Position).unit * 100
explodingFireBall.partWeld:Destroy()

I honestly tried my best explaining this. I'm probably overthinking it and it's something simple.

2 comments

0

That's a lot of code to sift through all at once, but I think the way I would do it is as soon as you remove the weld, call a RemoteFunction that returns the mouse's current position from a localscript.

0

@DropshipPilot Thanks, will try that now.

1 answer

If I'm right, what you want is:

In a LocalScript...

local Mouse = game.Players.LocalPlayer:GetMouse()

In a Script...

game.Players.PlayerAdded:connect(function(player)

local Mouse = player:GetMouse()

If it works, mark as the solution, please.

And as always, good scripting!

1 comment

0

Well looking at it, I've tried getting the mouse on the server script but mouse would just return as nil.

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