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

How do you get the Mouse.Hit.P in a script when it is stored in ServerScriptService?

local repstore = game:WaitForChild("ReplicatedStorage") local Remote = repstore:WaitForChild("SmokeFlyStart")

Remote.OnServerEvent:Connect(function(player)

local char = player.Character

	for i, v in pairs (char:GetChildren()) do
		if 	v.ClassName == "Part" or v.ClassName == "MeshPart" then
			v.Transparency = 1
			end		
	end
	local Smoke = game.Lighting.Smoke:Clone()
	Smoke.Parent = char.HumanoidRootPart
	local BV = Instance.new("BodyVelocity",char.HumanoidRootPart)
	BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	for i = 1,200 do 
		wait()
		char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position,***Mouse.Hit.p***)
		BV.Velocity = char.HumanoidRootPart.CFrame.lookVector*90
	end
	for i, v in pairs (char:GetChildren()) do
			if v.ClassName == "Part" or v.ClassName == "MeshPart" then
				if v.Name ~= "HumanoidRootPart" then 
				 v.Transparency = 0 
			end
		end
	Smoke:Destroy()	
	BV:Destroy()
	end

end)

I'm fairly new to scripting and this has been giving problem. Not sure if I'm suppose to create more variables. Is there a way to read the Mouse.Hit.p and transfer somehow?

6 comments

0

even though this causes a bit of latency, you should probably use remote events

0

^ and really, no need to WaitForChild on a service. That's stupid and they will exist. And don't use Lighting as storage, that is not what it's for.

0

yes.

0

Thats not really answer my question.

0

So what? I'm just giving tips so you can be a better coder.

0

Didn't meant that personally.

1 answer

u can t rly get mouse.Hit.p from a script; that has to be done locally(from a localscript) and transferred to a script. I recommend u get a localscript in all players and transfer the mouse.Hit.p via a remote event to the said script

what well do now is place a localscript in a script in the serverscriptservice to be cloned to all players

in script:

local item = script.LocalScript

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

game.Players.PlayerAdded:connect(function(player)
	local clone = item:Clone()
	clone.Parent = player:WaitForChild("Backpack")
	clone.Disabled = false
	
	wait(1)
	
	re:FireClient(player)
end)

re.OnServerEvent:connect(function(player, mpos)
	print(mpos)
end)

in localscript:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local repstore = game.ReplicatedStorage

local re = repstore:FindFirstChild("mouse_event") or repstore:WaitForChild("moues_event")

re.OnClientEvent:connect(function()
	re:FireServer(mouse.Hit.p)
end)

make sure the localscript is disabled; this will print out the player's mouse.Hit.p in approx. 1 second after a player has loaded in.

1 comment

0

connect is deprecated, use Connect. p is deprecated as well so use Position, and why are you cloning scripts everywhere? You don't need to do that.

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