Heyguys, I am learning about remote events and have been hitting a mistake recently. everytime I try to spawn a part on the position of the mouse, it doesnt work.
I’ve tried putting the lines in the local script, but I dont know if its possible to transfer a variable/information from the local script where its firing, into the server script that detects it.
The error code I get is: attempt to index nil with 'Hit'
, and I dont know what im doing wrong.
Local script:
local InvEvent = game:GetService("ReplicatedStorage"):WaitForChild("InvisEvent")
player = game:GetService("Players").LocalPlayer
tool.Activated:Connect(function()
InvEvent:FireServer()
end)
Server Script:
local replicatedstorage = game:GetService("ReplicatedStorage")
local InvEvent = Instance.new("RemoteEvent")
InvEvent.Name = "InvisEvent"
InvEvent.Parent = replicatedstorage
local tool = game.StarterPack.invisible
local spawnable = Instance.new("Part")
InvEvent.OnServerEvent:Connect(function(player)
local mouse= player:GetMouse()
local mouseposition = mouse.Hit.Position
spawnable.Position = mouseposition
spawnable.Parent = workspace
end)
If anyone can help me, or maybe explain something Im doing wrong, any help is appreciated.