trying to write a function that spawns a damaging part where the cursor Vector3 position is. No errors show up in output but the position where the part spawns is always in a random but unchanging position. FYI - some parts of the script have been omitted to save space but it's mostly just individual checks to see if other keys have been pressed
LocalScript
local UserInputService = game:GetService("UserInputService") local connect = game.ReplicatedStorage.Remotes.ddangys player = script.Parent.Parent mouse = player:GetMouse() mouseVector3Pos = mouse.Hit.Position mouseTarget = mouse.Target game:GetService("UserInputService").InputBegan:Connect(function(input, GPE) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.Q then local SelectedHero = player.stats:WaitForChild("SelectedHero").Value connect:FireServer("Q",SelectedHero, mouseVector3Pos, mouseTarget) print("try") script.Parent.Parent.PlayerGui.ScreenGui.Q.BackgroundColor3 = Color3.fromRGB(255,0,4) wait(.05) script.Parent.Parent.PlayerGui.ScreenGui.Q.BackgroundColor3 = Color3.fromRGB(255,255,255) end end)
ServerScript
local connect = game.ReplicatedStorage.Remotes.ddangys local module = require(script.abilityMod) connect.OnServerEvent:Connect(function(player,Key,SelectedHero,mouseVector3Pos,mouseTarget) if Key == "Q" then module[Key][SelectedHero](player, mouseVector3Pos, mouseTarget) end end)
ModuleScript (child of ServerScript)
module["Q"] = { ["Wizard"] = function(player, mouseVector3Pos, mouseTarget) local AOE = Instance.new("Part",player.Character) AOE.BrickColor = BrickColor.new("Toothpaste") AOE.Material = Enum.Material.Neon AOE.Anchored = true AOE.CanCollide = false AOE.Shape = "Cylinder" AOE.Position = mouseVector3Pos if AOE then print("Attack part exists") end print("Wizard pressed Q") end }
I've been wrestling with this for a while, but the part always just spawns in a random area. can someone suggest an alternate function or solution to correct this?