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

How does the RemoteEvent not work, it prints the Vector but doesn't shoot there?[New Issue]

Asked by 8 years ago

Error I'd assume is either transferring the hit position or, line 60, but it doesn't output anything.

Same LocalScript Code:

local Tool = script.Parent
local vExit = Tool:WaitForChild("Exit")
local Player = game:GetService("Players").LocalPlayer
local PointEvent = Instance.new("RemoteEvent")
PointEvent.Parent = script.Parent
PointEvent.Name = "PointEvent"


------------------------------------------------
function Equip(Mouse)
Wielder = Tool.Parent
workspacechar = Wielder.Name
local Humanoid = Wielder:FindFirstChild("Humanoid")
local HoldA = Tool:WaitForChild("Idle")
if Humanoid and Humanoid.Health >= 1 then
Hold = Humanoid:LoadAnimation(HoldA)
Hold:Play()
end
--[[
if Mouse == nil then
    Player:GetMouse()
else
    return
end]]
Mouse.Button1Down:connect(function()
    PointEvent:FireServer(Mouse.Hit.p)

end)


end

------------------------------------------------
function Unequip()
if Hold then
    Hold:Stop()
end

end
------------------------------------------



---------------------------------------

Tool.Equipped:connect(Equip)

New Script Code:

local Tool = script.Parent
local vExit = Tool:WaitForChild("Exit")
local Config = Tool:WaitForChild("Configuration")
local PointEvent = Tool:WaitForChild("PointEvent")


------------------------------------------------
function Equip()
Wielder = Tool.Parent
workspacechar = Wielder.Name
local Humanoid = Wielder:FindFirstChild("Humanoid")
local Player = game.Players:FindFirstChild(workspacechar)
FireS = Tool.Handle:WaitForChild("Fire")
Pump = Tool.Handle:WaitForChild("Pump")
Mouse = Player:GetMouse()
end

------------------------------------------------
function Unequip()

if FireS then
    FireS:Stop()
end

if Pump then
    Pump:Stop()
end

end
------------------------------------------
function Reload()
Tool.Enabled = false
for i = 1, 7 do
    Config.Ammo.Value = Config.Ammo.Value + 1
    Pump:Play()
    wait(FireS.TimeLength)
end 
Tool.Enabled = true
end
-----------------------------------------
function Fire()
PointEvent.OnServerEvent:connect(function(player, hit)
target = hit
print(hit)
end)
wait()
if Tool.Enabled == false then
    return
end
if Config.Ammo.Value <= 0 then
    Reload()
    return
end 

if FireS then
    FireS:Play()
end
Config.Ammo.Value = Config.Ammo.Value - 1
Tool.Enabled = false
for i = 1, math.random(7,10) do --number of bullets coming out
local ray = Ray.new(Tool.Exit.Position, ((target - Vector3.new(math.random(-0.25, 1), math.random(-1,2), math.random(-0.25, 1)) - Tool.Exit.Position)).unit * 45)
local part, position = workspace:FindPartOnRay(ray, game.Workspace:FindFirstChild(workspacechar), false, true)

local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Medium stone grey")
beam.FormFactor = "Custom"
beam.Material = "Plastic"
beam.Transparency = 0.915
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false

local distance = (Tool.Exit.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.05, 0.05, distance)
beam.CFrame = CFrame.new(Tool.Exit.CFrame.p, position) * CFrame.new(Tool.Exit.Position,Tool.Exit.CFrame.p, -distance / 2)

game:GetService("Debris"):AddItem(beam, 0.1)

if part then
    local humanoid = part.Parent:FindFirstChild("Humanoid")

    if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end

if humanoid then
     humanoid:TakeDamage(math.random(5.5,7))
                end
            end
        end
wait(.565)
Tool.Enabled = true
end
--end
---------------------------------------

Tool.Equipped:connect(Equip)
Tool.Unequipped:connect(Unequip)
Tool.Activated:connect(Fire)

EDIT: I have fixed this online but, upon joining the game it doesn't fire, nor does it make any errors, why is that now?

0
What line is the problem on? User#11440 120 — 8y
0
Line 60, where target is defined. Evadable 65 — 8y
0
Used* not defined. Evadable 65 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

When you FireServer, you don't need to specify the player, that is sent automatically as the first argument for the OnServerEvent.

Also when you fire the information, you only send the position (disregarding the player), yet in the event, you have specified a third argument, which would be nil as it's not being sent.

0
Interesting, so apparently, all I needed to do was put "if target ~= nil then" before the fire code but, it lags a little bit, which is a downside that isn't fixable I don't think. Evadable 65 — 8y
0
Edit: Nevermind, doesn't work in game strangely, but it doesn't output any errors either. Evadable 65 — 8y
Ad

Answer this question