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

I need a replacement for mouse.Hit.p ?

Asked by 8 years ago

One that does not ignore targetfilter. Any help? (I'm a little amateur with working the mouse)

This is all the coding you need to know:

Wait();
local max_power=125;--the maximum amount of power that can be reached
local deb=false;--is the mouse being held or not?
local throwing=false;--is the ball being thrown or not?
local power=0;--the current power being used
local keys={};--table for keys being pressed

--associative array for background
local frame_ary={
    ['BackgroundColor3']=Color3.new(50/255,50/255,50/255);
    ['BackgroundTransparency']=0.1;
    ['BorderColor3']=Color3.new(1,1,1);
    ['Position']=UDim2.new(0.1,0,0.5,0);
    ['Size']=UDim2.new(0.025,0,0.3,0);
};

--associative array for charge ball
local bar_ary={
    ['BackgroundColor3']=Color3.new(50/255,1,50/255);
    ['BorderSizePixel']=0;
};

--colors the bar the proper color
function color(bar)
    bar.BackgroundColor3=Color3.new(power/max_power,1-power/max_power,0);
end

--associative array for Instance type name
function doit(array,name)
    local a=Instance.new(name);
    for i,v in pairs(array) do
        if pcall(function() return a[i]; end) then
            a[i]=v;
    end end
    return a;
end

--throws the ball
function fire(v,power)
    local vCharacter = game.Players.LocalPlayer.Character;
    local vPlayer = game.Players.LocalPlayer;
    local thing = script.Parent:Clone();
    local missile = thing.Handle
    local spawnPos = vCharacter.PrimaryPart.Position    

    spawnPos  = spawnPos + (v * 10)
    targetPos = spawnPos + (v * power)

    missile.Position = spawnPos
    missile.Velocity = v * power
    missile.CanCollide = true
    missile.Elasticity = .05
    missile.Friction = .7
    missile.CFrame=CFrame.new(spawnPos,targetPos)*CFrame.Angles(math.rad(90),0,0);

    local bodyp = Instance.new("BodyVelocity")
    bodyp.maxForce = Vector3.new(1e3,1e3,1e3)
    bodyp.P = power*100;
    bodyp.velocity = (targetPos-missile.CFrame.p).unit*power
    bodyp.Parent = missile

    local new_script = script.Script:clone()
    new_script.Name=tostring(power);
    new_script.Disabled = false
    new_script.Parent = missile
    thing.Parent = game.Workspace

    game:GetService("Debris"):AddItem(script.Parent,0);
end

--if the handle is touched while in handoff position
script.Parent.Handle.Touched:connect(function(part)
    if keys['x'] and part.Parent:findFirstChild("Humanoid") then
        keys['x']=false;
        script.Parent.GripPos=Vector3.new(0.2,0.2,0.3);
        script.Parent.GripForward=Vector3.new(0.7688,0.4522,-0.4522);
        script.Parent.GripUp=     Vector3.new(-0.5687,0.8068,-0.16);
        script.Parent.GripRight=  Vector3.new(0.2925,0.3802,0.8774);
        script.Parent.Parent=part.Parent;
end end
);

--when the tool is equipped
script.Parent.Equipped:connect(function(mouse)
    mouse.Icon = "rbxasset://textures\\GunCursor.png";
--when clicked
    mouse.Button1Down:connect(function()
        power=0;
        throwing=true;
        deb=true;
        local sg=Instance.new("ScreenGui",game.Players.LocalPlayer.PlayerGui);
        local frame=doit(frame_ary,"Frame");
        frame.Parent=sg;
        local bar=doit(bar_ary,"Frame");
        bar.Parent=frame;
        while deb do
            power=power<max_power and power+8 or max_power;
            bar.Size=UDim2.new(1,0,power/max_power,0);
            bar.Position=UDim2.new(0,0,1-power/max_power,0);
            color(bar);
            Wait();
        end
        if throwing then
            game:GetService("Debris"):AddItem(sg,0);
            fire((mouse.Hit.p-game.Players.LocalPlayer.Character.Head.Position).unit,power);
            power=0;
    end end
    );

--when released
    mouse.Button1Up:connect(function()
        deb=false;
    end
    );

--when a key is pressed
    mouse.KeyDown:connect(function(key)
        keys[key]=true;
    --if handoff motion
        if key:lower()=="x" then
            while keys[key:lower()] do
            script.Parent.GripPos=Vector3.new(0,0.5,0);
            script.Parent.GripForward=Vector3.new(0,0,0);
            script.Parent.GripUp=     Vector3.new(0,0,0);
            script.Parent.GripRight=  Vector3.new(0,0,1);
                Wait();
            end
            script.Parent.GripPos=Vector3.new(0.2,0.2,0.3);
            script.Parent.GripForward=Vector3.new(0.7688,0.4522,-0.4522);
            script.Parent.GripUp=     Vector3.new(-0.5687,0.8068,-0.16);
            script.Parent.GripRight=  Vector3.new(0.2925,0.3802,0.8774);
    end end
    );

--when a key is released
    mouse.KeyUp:connect(function(key)
        keys[key:lower()]=false;
    end
    );
end
);

(can be found in almost any roblox football, such as this one: https://www.roblox.com/KillKays-Official-Football-item?id=269511297

0
What? You need a mouse.Hit.p that doesn't ignore targetFilter? Just turn off targetFilter theCJarmy7 1293 — 8y
0
But I need the targetfilter or the ball will throw backwards, into an invisible wall that is in the way of the camera Ethan_Waike 156 — 8y
0
So, let me get this straight. You need the mouse.Target to not be the wall, but you want the mouse.Hit.p to hit the wall? theCJarmy7 1293 — 8y
0
No, the targetfilter is an invisible wall. I want mouse.hit.p to not hit the wall Ethan_Waike 156 — 8y
View all comments (13 more)
0
So you need the target to be the wall, and the mouse.Hit.p to not hit the wall? theCJarmy7 1293 — 8y
0
The ball should throw past this wall. https://gyazo.com/2fe7bce4b53564080a7e78c7e7f3b194 Ethan_Waike 156 — 8y
0
So, the mouse.Hit.p needs to be behind the wall, and the target has to be behind it aswell? theCJarmy7 1293 — 8y
0
Couldn't you just make the ball CanCollide off until it hits the baseplate, or an invisible wall of the other side of the first one? Idk :3 User#11440 120 — 8y
0
Updated explanation Ethan_Waike 156 — 8y
0
You never defined power theCJarmy7 1293 — 8y
0
Or the mouse theCJarmy7 1293 — 8y
0
I was told I could use raycasting, not quite sure how it works though. Ethan_Waike 156 — 8y
0
Well I updated it to all 140 lines, didn't think you'd need most of them but I suppose it'll probably help you out Ethan_Waike 156 — 8y
0
Also, is that a free model? theCJarmy7 1293 — 8y
0
Indeed Ethan_Waike 156 — 8y
0
What'd I say about criticism? Ethan_Waike 156 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You could create your own method instead of using mouse.Target, or mouse.Hit. ROBLOX allows you to create formats for that kind of stuff.

Ad

Answer this question