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

Hit is not a valid member of CFrame?

Asked by 4 years ago

I am trying to make a script where when you click a player, they fly to you (not teleport), right now, it is a tool with a local script that when you click a person, it sends over the Mouse.Hit and Mouse.Target to a server script, but I keep getting the error Hit is not a valid member of CFrame. Here are the scripts.

Local script

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Cooldown = false 
local CDTime = 5
local Mouse = Player:GetMouse()

Tool.Activated:Connect(function()
if Cooldown then return end 
if Mouse.Target == nil then return end
print(Mouse.Target)
spawn(function()
    Cooldown = true
    wait(CDTime) 
    Cooldown = false 
end)

Tool.RemoteEvent:FireServer(Mouse.Hit, Mouse.Target) 

end)

Server Script

local Tool = script.Parent
local Cooldown = false 
local CDTime = 10


Tool.RemoteEvent.OnServerEvent:Connect(function(Player, Mouse)
if Cooldown then return end 
local char = Player.Character
local root = Player.Character.HumanoidRootPart


    spawn(function()
        Cooldown = true 
        wait(CDTime)
        Cooldown = false 
    end)

local bp = Instance.new("BodyPosition")
bp.Position = root.Position
bp.MaxForce = Vector3.new(1e9,1e9,1e9)
bp.Parent = Mouse.Hit.Parent
game.Debris:AddItem(bp,2)
end)

1 answer

Log in to vote
0
Answered by
compUcomp 417 Moderation Voter
4 years ago

On line 21 of your script you are accessing Mouse.Hit. Mouse is a parameter from your RemoteEvent, but in your LocalScript we see that it isn't being passed the mouse, it's being passed Mouse.Hit. So essentially, you are setting bp.Parent to Mouse.Hit.Hit! Mouse.Hit is a CFrame, so it gives you the error "Hit is not a valid member of CFrame". Also, remember that Mouse.Target is the part that the mouse is pointing to, and Mouse.Hit is the location of the mouse's cursor. The BodyPosition should be parented to the target, not the hit.

0
Thanks, you gave me a lot of information to work with. I changed the local script to only mouse.target, and I changed the server script line 21 to mouse.Target, but now I am getting the error "Target is not a valid member of Part" bowsercow 20 — 4y
0
Change the server script line 21 to just mouse. The LocalScript is fine. You've confused yourself with your variable names. I don't think you can actually pass the entire mouse object through a remote, since it's non-replicated, but you CAN pass CFrames and replicated parts. A better name for the parameter would be "MouseTarget", since that's what you pass into it. compUcomp 417 — 4y
1
I get it now, I'm passing mouse.Target to the server script as mouse, so I was doing Mouse.Target.Mouse.Target. Thanks so much. bowsercow 20 — 4y
0
Glad I could help :D compUcomp 417 — 4y
Ad

Answer this question