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

Raycasting through FilteringEnabled; how to?

Asked by 8 years ago
Edited 8 years ago

I'm trying to make a raycasting gun, very basic, however I can't work out how to transfer the target from LocalPlayer to ServerScriptService. Here is my code.

game.ReplicatedStorage.Mouse1Down.OnServerInvoke=function(player,tool)
    tool=tool
    mouse=game:GetService('Players'):findFirstChild(player.Name):GetMouse()
    shootRay(player,tool)
end

function shootRay(player, tool)
        print(mouse.hit.p)
        print(tool.Handle.CFrame.p)
        local ray = ((mouse.hit.p - tool.Handle.CFrame.p).unit*300)
        local part,position = workspace:findPartOnRay(ray, player.Character, false, true)
        local beam = Instance.new('Part',workspace)
        beam.BrickColor=BrickColor.new(Color3.fromRGB(255,0,0))
        beam.FormFactor='Custom'
        beam.Material='Neon'
        beam.Transparency=.25
        beam.Anchored=true
        beam.Locked=true
        beam.CanCollide=false
        local distance=(tool.Handle.CFrame.p-position).magnitude
        beam.Size=Vector3.new(0.3,0.3,distance)
        beam.CFrame=CFrame.new(tool.Handle.CFrame.p,position)*CFrame.new(0,0,-distance/2)
        game:GetService('Debris'):AddItem(beam, .1)
        if part then
            local humanoid=part.Parent:findFirstChild('Humanoid')
            if not humanoid then
                local humanoid=part.Parent.Parent:findFirstChild('Humanoid')
            end
            if humanoid then
                humanoid:TakeDamage(30)
        end
    end
end

The error I get is: (edit: Scriptblocked dude to line weird thingies happening)

20:13:33.343 - Unable to cast Vector3 to Ray
20:13:33.343 - Stack Begin
20:13:33.343 - Script 'ServerScriptService.gunFired', Line 11 - global shootRay
20:13:33.344 - Script 'ServerScriptService.gunFired', Line 4
20:13:33.344 - Stack End
20:13:33.344 - Unable to cast Vector3 to Ray
20:13:33.345 - Stack Begin
20:13:33.345 - Script 'Players.Player1.Backpack.Gun.LocalScript', Line 7
20:13:33.345 - Stack End

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

You should do the input through LocalScripts..

This WIKI page gives you a good insight on how to do that

And then process the logic on the server side. But you can simply replace the RemoteEvent as a RemoteFunction to return values back to the LocalScript.

But if your trying to transfer a value to the server script.. a simple RemoteEvent should suffice.

Event:FireServer(Parameters)

To fix some of your errors though try mouse.Hit.p

Notice the case sensitivity

Ad

Answer this question