Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why cant I Send Mouse With a remoteEvent To ServerScript?

Hello. You guys, i need help with something.. i am trying to get Mouse.Target With RemoteEvent. The thing is that i am not good at RemoteEvents And I dont know how To Send them to serverscripts. This is a example i did:

LocalScript:

local mouse = game.Players.LocalPlayer:GetMouse()
local RemoteEvent = game.ReplicatedStorage.RemoteEvent

RemoteEvent:FireServer(mouse.Target)

Server:

local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player,mouse)
  mouse.Target.Parent.Character.Humanoid:TakeDamage(40)
end)

Now The error says "Target is not a vaild member of Part". Help

7 comments

0

i edited the question just incase some problems

0

You should use raycasting. It usually solves problems like yours.

0

im sorry but i dont really know raycasting. can you explain? @Dovydas1118

1

you're already passing the mouse target, just remove .Target from the server script

0

ill test

0

it prints. But it does not Damage The player. @Leamir

0

remove the .Character also, mouse.Parent (on the server script) is already the character

1 answer

✓ Accepted answer

In your server script, you are already reciving the mouse target, also mouseTarget.Parent is already the character.

Btw, this script will error if you click on something that don't have a humanoid, you should add checks for that

--Server
local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player,mouse) -- in this case, mouse is already the target
  mouse.Parent.Humanoid:TakeDamage(40) -- mouse.Parent is already the character
end)

If this answers your question, please mark this answer as accepted :)

1 comment

0

Many thanks man. I had this problem in Half a month Lol. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.