How would I get this to work in game since a server script can only access the > GetMouse() < method in studio.

This is basically for a gas tank so when you press on a block you get a 'pipe' that follows your mouse and then when you hover over a 'FuelCap' on a vehicle it refuels it.

Help would be nice, thanks.

local active = false
local activePlayer = nil
local mouse = nil

local currentRay = nil

local currentCap = nil

local rayPart = Instance.new("Part")
rayPart.Name = "Pipe"
rayPart.Transparency = 0
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.SmoothNoOutlines
rayPart.BottomSurface = Enum.SurfaceType.SmoothNoOutlines
rayPart.FrontSurface = Enum.SurfaceType.SmoothNoOutlines
rayPart.BackSurface = Enum.SurfaceType.SmoothNoOutlines
rayPart.LeftSurface = Enum.SurfaceType.SmoothNoOutlines
rayPart.RightSurface = Enum.SurfaceType.SmoothNoOutlines
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.BrickColor = BrickColor.new("Storm blue")
rayPart.Reflectance = 0
rayPart.Material = Enum.Material.Metal

local function Reset()
	active = false
	activePlayer = nil
	mouse = nil
	if currentCap ~= nil then
		water.Refilling.Value = false 
	end
	if currentRay ~= nil then
		currentRay:Destroy()
	end
	currentCap = nil
	currentRay = nil
end

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if not active then
		Reset()
		activePlayer = player
		active = true
	elseif active then
		Reset()
	end
end)

while true do
	wait()
	if active and activePlayer ~= nil then
		local mouse = activePlayer:GetMouse()
		
		mouse.Button1Down:Connect(function()
			Reset()
		end)
			
		if currentRay ~= nil then
			mouse.TargetFilter = currentRay
		end
				
		if currentCap == nil then
			ray = Ray.new(script.Parent.Position, (mouse.Hit.p - script.Parent.Position).unit)
		else
			ray = Ray.new(script.Parent.Position, (currentCap.Position - script.Parent.Position).unit)
		end
		
		local hit = mouse.Target
			
		if hit ~= nil then
			if hit.Name == "WaterCap" and not hit:FindFirstChild("Connected") then
				currentCap = hit
				local connect = Instance.new("BoolValue")
				connect.Parent = currentCap
				water = currentCap.Parent.Parent:FindFirstChild("Water")
				if water then
						water.Refilling.Value = true 
				end
			end
		end
				
		local distance = (mouse.Hit.p - script.Parent.Position).magnitude
			
		if distance > 100 then
			distance = 100
		end
		
		if currentRay == nil then
			pipe = rayPart:clone()
		else
			pipe = currentRay
		end
			
		if currentCap ~= nil then
			position = currentCap.Position
		else
			position = mouse.Hit.p
			distance = distance-1
		end
			
		pipe.Size = Vector3.new(0.5, distance, 0.5)
		pipe.CFrame	= CFrame.new(position, script.Parent.Position) * CFrame.new(0, 0, -distance/2) * CFrame.Angles(math.rad(90),0,0)
		pipe.Parent	= script.Parent.Parent
			
		currentRay = pipe
			
		if currentCap ~= nil then
			activePlayer = nil
			active = false
			mouse = nil
		end
	end
end

[If you would have to rewrite it then tell me what I need to change/do so I can do it myself. Don't want to be making you do it for me]

1 comment

0

You would use a Remote Event. You would detect, on a local script, when the player clicks. Then, you would use a remote event to tell the server that. http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions