#RemoteEvent is firing wrong value

19 messages · Page 1 of 1 (latest)

signal tundra
#

I have a server side gun script firing the raycast hit part name and it correctly prints the parts name , I also have a server side barrel script that listens for the event and for simplicity sake prints a message if the name of the raycast result is equal to "testPart"

``fire.OnServerEvent:Connect(function(player, mouseHit)
--print("Fire event triggered by", player.Name)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")

local rayOrigin = muzzle.Position
--raycast stuff

local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

if raycastResult then
    local hitPart = raycastResult.Instance
    local hitPosition = raycastResult.Position
    local hitPartName = hitPart.Name  -- Ensure this is the name

    local hitNormal = raycastResult.Normal

    -- Return the name of the hit part to the client
    print("Firing event for hit part:", hitPartName)
    fire:FireClient(player, hitPartName)
    --print(hitPart.Name)

end)``

silver treeBOT
#

studio** You are now Level 5! **studio

signal tundra
#

Gun script ^

#

``local ReplicatedStorage = game:GetService("ReplicatedStorage")
local fire = ReplicatedStorage:WaitForChild("Fire")

local function onGunFire(player, hitPartName)
print("Received hitPartName:", hitPartName, type(hitPartName))

if hitPartName == "testPart" then
    print("explodddd")
    -- Your explosion logic here
end

end

fire.OnServerEvent:Connect(onGunFire)
print("Event listener set up")
``

#

Test script ^

#

The gun script correctly prints the name of the object it hits but the test script returns a bunch of random numbers ( probably cframe stuff)

#

For example

`` Firing event for hit part: Part - Server - GunMain:111

Received hitPartName: 366.251068, 9.50810909, 52.5245819, 0.829115331, -0.0127142332, -0.558933079, -2.06148252e-06, 0.999741316, -0.0227445029, 0.55907768, 0.0188589692, 0.828900814`` -- testScript

#

All the events are set up correctly i dont know why this wouldnt work

novel flame
#

FireClient's first argument is the player to send the rest of the arguments to

#

it doesn't come out in the result

signal tundra
novel flame
#

yes

#

remove player

signal tundra
#

let me send the rest of the script because i think i need the player i get errors if i dont have it

#

``fire.OnServerEvent:Connect(function(player, mouseHit)
print("Fire event triggered by", player.Name)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then
print("No Humanoid found in character")
return
end

--print("Humanoid found, proceeding with firing")



local rayOrigin = muzzle.Position
local rayDirection = (mouseHit.Position - muzzle.Position).Unit * velocity.Value + weaponAccuracy
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character}


local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

if raycastResult then
    local hitPart = raycastResult.Instance
    local hitPosition = raycastResult.Position
    local hitPartName = hitPart.Name  -- Ensure this is the name

    local hitNormal = raycastResult.Normal

    local eHumanoid = hitPart.Parent:FindFirstChild("Humanoid") or hitPart.Parent.Parent:FindFirstChild("Humanoid")

    if eHumanoid and eHumanoid ~= humanoid and eHumanoid.Health > 0 then
        local damage = damage.Value
        if hitPart.Name == "Head" or hitPart:IsA("Hat") then
            damage = damage * 2  -- Headshot multiplier
        end
        DamageAndTagHumanoid(player, eHumanoid, damage)
        print(damage, eHumanoid.Parent.Name)
        --print("Hit humanoid with damage:", damage)
    elseif not eHumanoid and (not hitPart.Anchored or (hitPart.CanCollide and hitPart.Anchored)) then
        TriggerObjectFunction(hitPart)
    end

    -- Return the name of the hit part to the client
    print("Firing event for hit part:", hitPartName)
    fire:FireClient(player, hitPartName)
    --print(hitPart.Name)
end

end)``

#

without player

#

so its sending the hitPartName over to the local player and not the server?

signal tundra
#

@novel flame any ideas?