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

Why does mouse.Hit.Position place this part in a constant position somewhere else? [SOLVED]

Asked by 1 year ago
Edited by T3_MasterGamer 1 year ago

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?

0
You set mouse.Hit.Position as a variable. Anything that is set as a variable will never change by itself. In line 12 of LocalScript, change mouseVector3Pos to mouse.Hit.Position, and change mouseTarget to mouse.Target. T3_MasterGamer 2189 — 1y
0
thanks for the help, it worked :) YoureTotallyScrewed 9 — 1y

Answer this question