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

How do you make a raycasting gun with RemoteObjects?

Asked by 10 years ago

I have a laser gun, and I am trying to make it work with FilteringEnabled. When I try to use it, it puts in the output 21:02:54.742 - TeamColor is not a valid member of WedgePart 21:02:54.743 - Script 'Workspace.FireLaser.Script', Line 8 21:02:54.744 - Stack End 21:02:54.745 - TeamColor is not a valid member of WedgePart 21:02:54.746 - Script 'Players.Player1.Backpack.Lazer Beam.LocalScript', Line 41 21:02:54.747 - Stack End when I click on a wedge. It says Part instead of WedgePart when I click on a part. Here is the main code for the laser gun:

--Other unrelated code
local user = tool.Parent    
local person = game.Players:GetPlayerFromCharacter(user)
local Gui = person.PlayerGui.AmmoGui
function onClick()
        click = true
        while click do
            if Debounce == false then
                Debounce = true
                if Gui.Energy.Value > 0 then
                    Gui.Energy.Value = Gui.Energy.Value - 1 
                    Gui.Frame.TextLabel.Text = Gui.Energy.Value     
                    tool.Handle.LazerBoom:play()
                    local ray = Ray.new(tool.Handle.CFrame.p, ((mouse.Hit.p + Vector3.new((math.random(-100, 100)/100), (math.random(-100, 100)/100), (math.random(-100, 100)/100))) - tool.Handle.CFrame.p).unit*300)
                    local hit, position = game.Workspace:FindPartOnRay(ray, user)
                    local distance = (position - tool.Handle.CFrame.p).magnitude
                    --Line 41 below V
                    local isFired = game.Workspace.FireLaser:InvokeServer(game.Workspace:FindPartOnRay(ray, user), person, (position - tool.Handle.CFrame.p).magnitude, CFrame.new(position, tool.Handle.CFrame.p) * CFrame.new(0, 0, -distance/2))
                    repeat wait() until isFired == true 
                    wait(0.15)
                else script.Parent.Handle.NoEnergy:play() 
                    click = false 
                end
            Debounce = false
            end
        end 
    end
--More unrelated code

And the RemoteFunction:

function script.Parent.OnServerInvoke(hit, person, distance, CFrameValue)
    local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        humanoid:TakeDamage(10)
    end
    local rayPart = Instance.new("Part", user)
    rayPart.Name          = "RayPart"
    rayPart.BrickColor    = person.TeamColor
    rayPart.Anchored      = true
    rayPart.CanCollide    = false
    rayPart.TopSurface    = Enum.SurfaceType.Smooth
    rayPart.BottomSurface = Enum.SurfaceType.Smooth
    rayPart.formFactor    = Enum.FormFactor.Custom
    rayPart.Size          = Vector3.new(0.2, 0.2, distance)
    rayPart.CFrame        = CFrameValue
    game.Debris:AddItem(rayPart, 0.1)
end

Sorry if I am making an obvious mistake, I just started with RemoteObjects.

1 answer

Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

If it's a LocalScript, just use game.Players.LocalPlayer for the variable definition of person and user isn't even needed.

0
That's great and all, but it doesn't solve my problem. User#348 0 — 10y
0
And also, I just noticed this, in the RemoteFunction's code, it has the variable 'user' called, but not defined. Tkdriverx 514 — 10y
0
Ok, I changed that to player.Character, and now it's saying "Character is not a valid member of part" on line 6 of the remotefunction code and line 41 of the localscript. User#348 0 — 10y
0
Because "player" apparently is defined as a part. Recheck the entire code to see where 'player' may accidentally have been set to a part. Tkdriverx 514 — 10y
Ad

Answer this question