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

How Could i make this wand Shoot Spells in the Mouse's Direction?

Alright so I'm trying to make a HP Wand, and i'm facing a Setback, RN the Only way to make my wands work is Lookvector, I don't know How to Make it Face the Way my Mouse is Facing, Everything else Works Fine. Heres my Code

Local

local ReplicatedStorage = game.ReplicatedStorage
local event = ReplicatedStorage.AvadaKedavra
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Green = script.Parent.Attachment.Green
local Purple = script.Parent.Attachment.Purple
local Blue = script.Parent.Attachment.Blue
local Orange = script.Parent.Attachment.Orange
local Red = script.Parent.Attachment.Red
local Pink = script.Parent.Attachment.Pink

player.Chatted:Connect(function(msg)
	local msg = msg:lower()
	if msg:match("avada kedavra") then
		local spell = true
		Green.Enabled = true
		-- Clicked
		mouse.Button1Down:Connect(function()
			if spell then
		event:FireServer(mouse.Hit.p)
			Green.Enabled = false
				spell = false
			end
		end)
	end
end)

Server

local Spell = game.ServerStorage:WaitForChild("Spell")

game.ReplicatedStorage.AvadaKedavra.OnServerEvent:Connect(function(player)
	local character = player.Character
	local newSpell = Spell:Clone()
	newSpell.CFrame = character.HumanoidRootPart.CFrame
	
	
	local bodyVelocity = Instance.new("BodyVelocity")
	bodyVelocity.MaxForce = Vector3.new(500,500,500)
	bodyVelocity.Velocity = (character.HumanoidRootPart.CFrame.lookVector*250)
	bodyVelocity.Parent = newSpell
	
	newSpell.Parent = workspace
	
	local touchConn
	
	touchConn = newSpell.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent.Name ~= player.Name then
				hit.Parent:BreakJoints()
				if touchConn ~= nil then touchConn:Disconnect() end
				local Debris = game.ServerStorage.Debris:Clone()
				Debris.Parent = newSpell
				bodyVelocity:Destroy()
				wait(2)
				newSpell:Destroy()
			end
		end
	end)
	
	
	wait(30)

	if touchConn == nil then touchConn:Disconnect() end
	local Debris = game.ServerStorage.Debris:Clone()
	Debris.Parent = newSpell
	bodyVelocity:Destroy()
	wait(2)
	newSpell:Destroy()
end)

Could anyone Help me Figure this Out?

4 comments

0

can't you just do mouse.hit.p?

0

could i get some code?

1 answer

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