CFrame returns as the username of the player who activates RemoteEvent

Hello, I am trying to send a CFrame to a RemoteEvent I have created (Shown below). This CFrame comes from a LocalScript that is in the StarterPlayerScripts section of the Explorer (This will also be shown below). The CFrame comes from the location of the player’s cursor and is sent as an argument to the RemoteEvent.


The LocalScript code:

local RS = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

local UIS = game:GetService("UserInputService")

local function GetCframe() --function to get the CFrame
	local CoordX = Mouse.Hit.X 
	local CoordY = Mouse.Hit.Y
	local CoordZ = Mouse.Hit.Z
	
	local LookPos = CFrame.new(CoordX, CoordY, CoordZ)

	return LookPos
end

Debounce = false

UIS.InputBegan:Connect(function(input) --function that takes user input and activates the RemoteEvent
	if Debounce == false then
		if input.KeyCode == Enum.KeyCode.E then
			Debounce = true
			local Coords = GetCframe()
			game.ReplicatedStorage.GrappleEvent:FireServer(Coords)
			task.wait(5)
			Debounce = false
		end
	end
end)

The RemoteEvent code:

local GrappleEvent = Instance.new("RemoteEvent", game.ReplicatedStorage)
GrappleEvent.Name = "GrappleEvent"

GrappleEvent.OnServerEvent:Connect(function(TargetCoords) --the RemoteEvent that takes the argument
	print(TargetCoords)
end)

My main issue is that the event always returns the CFrame data as the username of the player who the RemoteEvent is activating for instead of the respective values (Refer to the image below).



I have yet to find a solution to this problem and have tried multiple things:

  1. Using the GetCFrame function to return the Coords directly into the argument
  2. Using a variable to pass the argument

and any variations of these that I could think of.

If any body has an idea/solution, it would be greatly appreciated if you could share it here.

This is because .OnServerEvent’s first parameter is always the player who fired the event. Simply:

local GrappleEvent = Instance.new("RemoteEvent", game.ReplicatedStorage)
GrappleEvent.Name = "GrappleEvent"

GrappleEvent.OnServerEvent:Connect(function(player, TargetCoords) --the RemoteEvent that takes the argument
	print(TargetCoords)
end)

image
I can’t believe that worked. Thanks dude, I’m kinda dumb sometimes.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.